WAP- Given two integers 20 and 10, write a program that uses a function add() to add these two numbers and sub() to find the difference of these two numbers and then display the sum and difference in the following form:

20 + 10 = 30
20 – 10 = 10

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.7, page 21

#include <stdio.h>

int add(int a, int b)
{return (a+b);
}

int sub(int a, int b)
{return (a-b);
}

#define A 20
#define B 10

int main(void)
{printf("\n\n");

printf("%d  +  %d  =  %d\n",A, B, add(A,B));
printf("%d  +  %d  =  %d",A,B,sub(A,B));

printf("\n\n");
return 0;
}

Comments

Post a Comment

Kindly keep your comments on-topic and don't spam.