Calculation of largest no as they are entered.

Discussion in 'C' started by coderzone, Apr 5, 2006.

  1. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    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:
    #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);
    }
     
  2. rai_gandalf

    rai_gandalf New Member

    Joined:
    Nov 4, 2005
    Messages:
    46
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Final Year Comp Engg
    Location:
    Mumbai
    Home Page:
    http://mindpuncture.blogspot.com
    Thx. May be useful 4 some of the C progs I hav in mind.

    Ciao,
    Rajiv

    ;)
     
  3. debleena_doll2002

    debleena_doll2002 New Member

    Joined:
    Feb 5, 2008
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    0

    :iagree:
     
  4. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
  5. crazytolearn57

    crazytolearn57 New Member

    Joined:
    Feb 14, 2008
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    0
  6. aisha.ansari84

    aisha.ansari84 New Member

    Joined:
    Feb 13, 2008
    Messages:
    82
    Likes Received:
    1
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice