Write a C program to find the greatest of three numbers.
int main() {
int num1, num2, num3;
/* input three values from user */
printf("Enter three numbers:");
scanf("%d%d%d", &num1, &num2, &num3);
if (num1 > num2) {
if (num1 > num3) {
printf("%d is the greatest\n", num1);
} else {
printf("%d is the greatest\n", num3);
}
} else if (num2 > num3) {
printf("%d is the greatest\n", num2);
} else {
printf("%d is the greatest\n", num3);
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter three numbers:100 200 50
200 is the greatest
Enter three numbers:100 200 50
200 is the greatest
No comments:
Post a Comment