Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Programs (http://www.go4expert.com/forums/programs-t24221/)

shiwalivaish 20Dec2010 15:43

Programs
 
WAP to find smallest among two numbers using if-else condition

Kyuuqsoft 15Feb2011 20:05

Re: Programs
 
try type activate.

lionaneesh 21Feb2011 03:38

Re: Programs
 
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


All times are GMT +5.5. The time now is 23:28.