This blog is under construction

Saturday 22 June 2013

C program to find largest of three numbers

Write a C program to find the greatest of three numbers.


  #include <stdio.h>
  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



No comments:

Post a Comment