Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Iterative statement



" ; " after loop



Header file



Test expression



Working with switch case




Array_interchange large and smallest number




// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include<stdio.h> #include<math.h> #define pf printf int main() { int n,i,large=-9999,small=9999,large_pos,small_pos,temp,arr[1000]; pf("Enter the number of element in the array: "); scanf("%d",&n); //taking array element pf("\nEnter the element of the array: "); for(i=0;i < n;i++) { scanf("%d",&arr[i]); //checking large number if(arr[i]>large) { large=arr[i]; large_pos=i; } //checking small number if(arr[i] < small) { small=arr[i]; small_pos=i; } } //printing optional output pf("\nThe largest number of the array= %d",large); pf("\nThe position of the largest number= %d",large_pos); pf("\nThe smallest number of the array= %d",small); pf("\nThe position of the smallest number= %d",small_pos); //interchanging large and small number temp=arr[large_pos]; arr[large_pos]=arr[small_pos]; arr[small_pos]=temp; //printing final output after interchange pf("\nThe new array is:"); for(i=0;i < n;i++) pf("\t %d",arr[i]); return 0; }
OUTPUT:


© 2018 - All rights reserved