Program to find largest of n numbers in c





Simple program of c find the largest number

#include<stdio.h>
int main(){
  int n,num,i;
  int big;
  
  printf("Enter the values of n: ");
  scanf("%d",&n);
 
  printf("Number %d",1);
  scanf("%d",&big);

  for(i=2;i<=n;i++){
    printf("Number %d: ",i);
    scanf("%d",&num);

    if(big<num)
      big=num;
  }
  
  printf("Largest number is: %d",big);

  return 0;
}

Sample Output:
Enter the values of n:
Number 1: 12
Number 2: 32
Number 3: 35
Largest number is: 35





6 comments:

  1. whats the differrent btween

    x=int(b);
    x=abs(b);

    ReplyDelete
  2. It's better to initialize big with INT_MIN, and then check each input number with respect to big.

    ReplyDelete
  3. #include
    void main(){
    int i,j,num[20],n,big;

    printf("Enter the number of Array: ");
    scanf("%d",&n);

    printf("Enter Numbers ");
    for(i=1;i<=n;i++)
    scanf("%d",&num[i]);

    big=num[0];

    for(j=2;j<=n;j++){
    if(big<num[j])
    big=num[j];
    }

    printf("Largest number is: %d",big);

    }

    ReplyDelete
    Replies
    1. #include
      void main(){
      int i,j,num[4],big;



      printf("Enter 3 Numbers\n ");
      for(i=0;i<3;i++)
      scanf("%d",&num[i]);

      big=num[0];

      for(j=1;j<3;j++){
      if(big<num[j])
      big=num[j];
      }

      printf("Largest number is: %d",big);

      }

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. #include
    #include

    int main()
    {
    int n,num,big
    ;
    printf("Enter the length of array:- ");
    scanf("%d",&n);
    int a[n],i,j;
    for(i=0;i<n;i++)
    {
    printf("\n a[%d]=",i);
    scanf("%d",&a[i]);
    }
    big=a[0];
    for(i=1;i<n;i++)
    {
    if(big<a[i])
    {
    big=a[i];
    }
    }
    printf("greater no:-%d",big);
    return 0;
    }

    ReplyDelete