Calculation of largest no as they are entered.

coderzone's Avatar author of Calculation of largest no as they are entered.
This is an article on Calculation of largest no as they are entered. in C.
The below program calculates the largest no among the no entered but it just calculates as user inputs them. This can be used with files and as you move ahead in file you can store the max and the min value in a variable when parsing the file.
Code: C
#include<stdio.h>

int largest(int,int);

void main()
{
    int n,m,i;
    printf("Go on entering numbers\n");
    scanf("%d",&n);
    for(i=1;i<=10;i++)
    {
        scanf("%d",&m);
        m=largest(n,m);
        printf("%d\t",m); /*prints the largest of the number inputed till now*/
        n=m;
    }
}
int largest(int n,int m)
{
    if(n>m)
        m=n;
    return(m);
}
0
rai_gandalf's Avatar, Join Date: Nov 2005
Go4Expert Member
Thx. May be useful 4 some of the C progs I hav in mind.

Ciao,
Rajiv

0
debleena_doll2002's Avatar
Ambitious contributor
Quote:
Originally Posted by rai_gandalf
Thx. May be useful 4 some of the C progs I hav in mind.

Ciao,
Rajiv


0
lead.smart34's Avatar, Join Date: Feb 2008
Contributor
good info
0
crazytolearn57's Avatar, Join Date: Feb 2008
Go4Expert Member
good one
0
aisha.ansari84's Avatar, Join Date: Feb 2008
Contributor
good one