Pages

Sunday, November 02, 2014

Write a program that calculate simple calculation by function

INPUT:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
int sum(int a, int b)
{
    return (a + b);
}
int main()
{
    int a, b;
    char op;
    printf("Enter two integer and one operator(+,-,*,/):\t");
    scanf("%d %d %c", &a, &b, &op);
    switch(op) {
    case'+':
        printf("%d + %d = %d", a, b, a+b);
        break;
    case'-':
        printf("%d - %d = %d", a, b, a-b);
        break;
    case'*':
        printf("%d * %d = %d", a, b, a*b);
        break;
    case'/':
        printf("%d / %d = %d", a, b, a/b);
        break;
    default:
        printf("Incorrect Output.");
    }//switch
}//main()

OutPut:


Enter two integer and one operator(+,-,*,/): 15 3 /
15 / 3 = 5

No comments:

Post a Comment