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





8 comments:

UNMAD said...

whats the differrent btween

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

Anand said...

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

Unknown said...

#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);

}

Unknown said...

#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);

}

SindhujaSelvaraj said...
This comment has been removed by the author.
Unknown said...

#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;
}

Unknown said...

Tx

Pavan said...

#include
#include
void main()
{
int l;
float area;
printf("\n\n\t\t length:");
scanf("%d",&l);

area=l*l;

printf("\n\n\t\tarea of square:%.3f",area);

getch();
}