Input 3 Arguments and Operate Appropriately on the Numbers.pdf

  • No School
  • AA 1
  • abinithyogi
  • 3

This preview shows page 1 - 3 out of 3 pages.

C Program to Input 3 Arguments and Operate Appropriately on theNumbersThis is a C Program to input 3 arguments and operate appropriately on the numbers.Problem DescriptionThis program take 3 arguments as input and operate appropriately on the numbers.Problem Solution1. Take two numbers and a operator as 3 arguments.2. Use switch statement to test the operator.3. According to the operator, do the operation and exit.advertisementProgram/Source CodeHere is source code of the C Program to input 3 arguments and operate appropriately on thenumbers. The C program is successfully compiled and run on a Linux system. The programoutput is also shown below.1. /* 2. * C Program to Input 3 Arguments and Operate Appropriately on the 3. * Numbers4. */5. #include <stdio.h>6. 7. void main(int argc, char * argv[])8. {9. int a, b, result;10. char ch;11. 12. printf("arguments entered: \n");13. a = atoi(argv[1]);14. b = atoi(argv[2]);15. ch = *argv[3];16. printf("%d %d %c", a, b, ch);17. switch (ch)18. {19. case '+':20. result = a + b;21. break;22. case '-':
Background image
Program Explanation1. Take two numbers and a operator as input and store it in the variables a, b and ch respectively.
Background image
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture