Monday 17 October 2011

17-10-2011 Cheking of Greatest number Using a function


/* This program takes three integers from user, calls a function to compares which one is greatest
and shows results inside that function.*/
#include<stdio.h>
#include<conio.h>
/*declaring function*/
void check(int, int, int);
int main ()
{
    /*declaring veriables*/
    int num11, num22, num33;
  
    /*prompt to take the input*/
    printf("Please enter three integers, remember pressing enter after every one: \n");
   
    /*taking input*/
    scanf("%d%d%d",&num11,&num22,&num33);
    check(num11, num22,num33);
    getche();
    return 0;
}
/*Defining function*/
void check(int num1, int num2,int num3)
{
    /*comparison and printing results*/
    printf("\n\nResult: \n");
    printf("___________\n\n");
    if (num1 > num2 && num1 > num3)
    {
         printf("%d is greatest!",num1);
    }
    else if (num2 > num1 && num2 > num3)
    {
         printf("%d is greatest!",num2);
    }
    else if (num3 > num1 && num3 > num2)
    {
         printf("%d is greatest!",num3);
    }
    else if (num1 == num2 && num1 == num3)
    {
         printf("All of the given digits are equal.");
    }
    else
    {
         printf("This is some other case not defined in the program!");
    }
   
}


No comments:

Post a Comment