This blog is under construction

Monday 10 June 2013

C program to find the greatest of two numbers using if statement

Write a C program to find the greatest of two numbers using if statement.



  /* C program to find greatest of two numbers */
  #include <stdio.h>
  int main() {
        int num1, num2;
        printf("Enter value for 1st number:");
        scanf("%d", &num1);
        printf("Enter value for 2nd number:");
        scanf("%d", &num2);
        if (num1 > num2)
                printf("%d is the greatest\n", num1);
        else
                printf("%d is the greatest\n", num2);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter value for 1st number:100
  Enter value for 2nd number:501
  501 is the greatest



No comments:

Post a Comment