Programs

Discussion in 'Programming' started by shiwalivaish, Dec 20, 2010.

  1. shiwalivaish

    shiwalivaish New Member

    Joined:
    Dec 20, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    WAP to find smallest among two numbers using if-else condition
     
  2. Kyuuqsoft

    Kyuuqsoft New Member

    Joined:
    Feb 14, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    try type activate.
     
  3. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    greater_check.c
    Code:
    #include<stdio.h>
    
    #define EQUAL_ERROR 0
    //This function inputs 2 numbers and returns the greater one..
    // Returns zero if the numbers are equal
    int max(no1,no2)
    {
    	if(no1 > no2)
    	{
    		return(no1);
    	}
    	else if(no1 < no2)
    	{
    		return(no2);
    	}
    	else
    	{
    		return(0); // If the no's are equal
    	}
    }
    
    int main()
    {
    	int no1 = 0 , no2 = 0; // Declare and initialise integers
    	int greater = 0; // The holder of the greater no
    	printf("Please enter 2 numbers seperated by a [space] and the program will tell you which one is greater :- \n");
    	scanf("%d %d",&no1,&no2);
    	greater = max(no1,no2);
    	
    	// ERROR CHECKING
    	// Check for errors
    	if(greater == EQUAL_ERROR)
    	{
    		printf("The numbers input are equal\n");
    		return(-1);
    	}
    	// else we are clean print the outut
    	else
    	{
    		printf("%d is greater\n",greater);
    	}
    	return(0);
    }
    

    Compiling :-


    Code:
    gcc greater_check.c -o greater_check
    
     
    shabbir likes this.

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