C Programming Tutorial

Advertisements

Write a program to find the largest of n number in C



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int arr[10]; 
              int i,lrg,pos=0;
              clrscr();

              for(i=0;i<10;i++)
              {
                 printf("Enter any number : "); 
                 scanf("%d",&arr[i]); 
              }
              
              lrg = arr[0];
              
              for(i=1;i<=10;i++)
              {
                     if(lrg < arr[i])
                     {
                        lrg = arr[i];
                        pos = i;
                     }
              }
                           
              printf("\nThe largest number is %d found at %d.",lrg,pos);               

              getch();
       }

   Output : 

              Enter any number : 78
              Enter any number : 45
              Enter any number : 12
              Enter any number : 89
              Enter any number : 56
              Enter any number : 23
              Enter any number : 79
              Enter any number : 46
              Enter any number : 13
              Enter any number : 82
              
              The largest number is 89 found at 3.




Advertisement