Programs

shiwalivaish's Avatar, Join Date: Dec 2010
Newbie Member
WAP to find smallest among two numbers using if-else condition
Kyuuqsoft's Avatar, Join Date: Feb 2011
Light Poster
try type activate.
lionaneesh's Avatar, Join Date: Mar 2010
Invasive contributor
greater_check.c
Code: c
#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 like this