Labels

Thursday, December 17, 2015

The largest of three numbers;

A C program to find the largest of three numbers;

#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter first number ");
scanf("%d",&a);
printf("Enter second number ");
scanf("%d",&b);
printf("Enter third number ");
scanf("%d",&c);
if(a>b)
{
if(a>c)
printf("First is largest\n");
}
else
{
if(b>c)
printf("Second is largest\n");
else
printf("Third is largest\n");
}
return 0;
}
Largest of three number
Largest of three number

To compile this program in Linux:
  1. Save this file with extension .c
  2. g++ compiler come pre installed in linux. Type this in terminal g++ max.c -o max. Here, I have assumed that the file name is max.c. -o array will provide me with an output file with extension exe file and name max.
  3. Now, run this file typing ./max and press enter.
To compile this program using cmd:
  1. Save this file with extension.c
  2. Type this in the cmd g++ max.c -o max.
  3. To run type max and press enter.
Note: To use g++ compiler in windows user has to install these compiler by itself as g++ compiler does not come per installed in windows operating system.




No comments:

Post a Comment