Implement a C code that take a 4 integer numbers in array the print
1- The array sorted
2-The average
3-The minimum number
4- The maximum number
C code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <stdio.h> #include <stdlib.h> int main() { int a[4]; int i=0 , j=0 ; int maxvalue=0; int minvalue; float averagevalue=0; int sum=0; int temp =0 ; printf("please enter arrary of 4 intger numbers :\n"); for (i=0 ; i < 4 ; i++) { scanf("%d",&a[i]); } for (i=0 ; i < 4 ; i++) { for (j=0 ; j < 4 ; j++){ if( a[i]< a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } for (i=0 ; i < 4 ; i++) { printf("%d",a[i]);} for (i=0 ; i <= 3 ; i++) { sum=sum +a[i];} averagevalue=sum / 4 ; printf("\nThe average value = %f \n",averagevalue); for (i=0 ; i <= 3 ; i++ ) { if (a[i]> maxvalue ) maxvalue = a[i]; } printf("The maxmuim value = %d \n",maxvalue); minvalue=maxvalue; for (i=0 ; i <= 3 ; i++ ) { if (a[i] < minvalue ) minvalue= a[i]; } printf("The minimum value = %d \n",minvalue); return 0; } |
Output :
0 Comment to "Array (Sort,Average,Maximum,Minimum)"
Post a Comment