Wednesday

Write a C program to input ‘n’ numbers and find out the largest and smallest number.

#include<stdio.h>
#include<conio.h>
void main()
  {
    int n,i,num[100],g,s;
    clrscr();
    printf("\nEnter how many numbers?");
    scanf("%d",&n);
    printf("\nEnter %d numbers",n);
    for(i=0;i<n;i++)
     scanf("%d",&num[i]);
    g=num[0];
    s=num[0];
    for(i=1;i<n;i++)
     {
      if (num[i]>g)
       g=num[i];
      if(num[i]<s)
       s=num[i];
     }
    printf("\nThe greatest number is %d",g);
    printf("\nThe smallest number is %d",s);
  getch();
}

No comments:

Post a Comment

Rahul-Notes