Problem: Find the Max/largest and Min/smallest number using array
Input : 20, 5, 7, 23, 2
Output : Max:myArray[3]=23, Min:myArray[4]=2
Input : 20, 5, 7, 23, 2
Output : Max:myArray[3]=23, Min:myArray[4]=2
- #include <stdio.h>
- int main()
- {
- int myArray[]={20, 5, 7, 23, 2};
- int Max, Min;
- Max=myArray[0];
- Min=myArray[0];
- int i, j, k;
- j=k=0;
- for(i=1; i<5; i++) {
- if (myArray[i] > Max) {
- Max=myArray[i];
- j=i;
- }
- else if(myArray[i] < Min){
- Min=myArray[i];
- k=i;
- }
- }
- printf("Max:myArray[%d]=%d, Min:myArray[%d]=%d\n", j, Max, k, Min);
- return 0;
- }
একটি মন্তব্য পোস্ট করুন