1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Programs

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

  1. shiwalivaish

    shiwalivaish New Member

    WAP to find smallest among two numbers using if-else condition
     
  2. Kyuuqsoft

    Kyuuqsoft New Member

    try type activate.
     
  3. lionaneesh

    lionaneesh New Member

    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