C program to find smallest and largest array element

C program to find smallest and largest array element


 /*************************************************

 C program to find smallest and largest array element

 * **************************************************/

 #include<stdio.h>

 #include<conio.h>

 void main()

 {

     int arr[20];

     int i,n;

     int large,small;

     printf("How many elements you want\n");

     scanf("%d",&n);

     printf("Enter array elements are\n");

     for(i=0;i<n;i++)

     {

         scanf("%d",&arr[i]);

         large=small=arr[0];

     }

     printf("The array elements are\n");

     for(i=1;i<n;i++)

     {

         printf("%d\t",arr[i]);

         if(arr[i]>large)

         large=arr[i];

         

         if(arr[i]<small)

         small=arr[i];

         

         

     }

     printf("\nThe largest array element is %d\n",large);

     printf("The smallest array element is %d\n",small);

     printf("End of program");

             

 }

How many elements you want

10

Enter array elements are

45

6

8

9

9

1

1

88

90

70

The array elements are

45 6 8 9 9 1 1 88 90 70

The largest array element is 90

The smallest array element is 1

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या