Thursday, January 20, 2011

Overview of C

Given two integers 20 and 10, write a program that uses a function add() to add these two numbers
and sub() to find the defference of these two numbers and then display the sum and defferences in
the following form:
20 + 10 =30
20 - 10 = 10
#include<stdio.h>
int add(int a,int b);                       /****function declaration****/


int sub(int a,int b);                        /****function declaration****/
void main()
{
int x,y,z;
x=20;
y=10;
z=add(x,y);                                  /****function call****/
printf("%d + %d = %d",x,y,z);
printf("\n");
z=sub(x,y);                                  /****function call****/
printf("%d + %d = %d",x,y,z);
getch();
}


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


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

No comments:

Post a Comment