C Programming

Greatest Number

Learn C programming by example for find Greatest number from user given four numbers

5/19/2018
0 views
c-greatest-number.cC
#include<stdio.h>

int main() {
	int a, b, c, d;
	printf("\nEnter 4 number for comparison:\n");

	/* Received more than one integer type value from user */
	scanf("%d %d %d %d",&a, &b, &c, &d);

	/* If condition for checking greatest value from two variables */
	if(a > b) {

		/* If 'a' is greater than 'b' */
		if(a > c) {
			if(a > d)
				printf("Greatest Number is: %d\n", a);
			else
				printf("Greatest Number is: %d\n", d);
		}
		else {
			if(c > d)
				printf("Greatest Number is: %d\n", c);
			else
				printf("Greatest Number is: %d\n", d);
		}
	}
	else {

		/* If 'b' is greater than 'a' */
		if(b > c) {
			if(b > d)
				printf("Greatest Number is: %d\n", b);
			else
				printf("Greatest Number is: %d\n", d);
		}
		else {
			if(c > d)
				printf("Greatest Number is: %d\n", c);
			else
				printf("Greatest Number is: %d\n", d);
		}
	}
	return 0;
}


/* Output */
/*
  Enter 4 number for comparison:
  4
  3
  7
  2

  Greatest Number is 7
 */
CC codingC programmingGreatest number

Related Examples

Mashable is a global, multi-platform media and entertainment company For more queries and news contact us on this
Email: info@mashablepartners.com