Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Test expression



" ; " after loop



Working with switch case



Iterative statement



Specifer




Array_print largest and smallest number with position separately




// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include<stdio.h> #include<math.h> #define pf printf int main() { int i,n,arr[1000],max=-9999,small=9999,pos1,pos2; pf("Enter the number of element in the array: "); scanf("%d",&n); //taking array element pf("\nEnter the array element: "); for(i=0;i < n;i++) scanf("%d",&arr[i]); //finding maximum number and its position for(i=0;i < n;i++) { if(arr[i]>max) { max = arr[i]; pos1 = i; } } //finding minimum number and its position for(i=0;i < n;i++) { if(arr[i] < small) { small = arr[i]; pos2 = i; } } //printing desired output pf("\nThe maximum number is: %d",max); pf("\nThe position of the maximum number: %d",pos1); pf("\nThe small number is: %d",small); pf("\nThe position of the small number: %d",pos2); return 0; }
OUTPUT:


© 2018 - All rights reserved