# C program to Find Sum of numbers and Swap of two numbers using third variable and without using third variable

C PROGRAM TO FIND SUM OF THREE NUMBERS:-

#include
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d",a+b+c);

}

INPUT:-
4
8
2

OUTPUT:-

14

The explaination of this program is very Simple , First of all we declared three  int type variables that is a,b,c
then we took input of their values using scanf() function,
IN C language %d is used for Integer data type
%f is used for float data type
%lf is used for float data type
then for giving the output on the console screen we used printf() function and computed the sum of three no. using arithematic operator '+'.

We can find sum of n numbers too but for that we need to understand the concept of array in C so will work on that too soon.

C PROGRAM TO SWAP TWO NUMBERS USING THIRD VARIABLES:-

#include

int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("After Swap a=%d\tb=%d",a,b); }

INPUT:-
12
26

OUTPUT:-

a=26
b=12

C PROGRAM TO SWAP TWO NUMBERS WITHOUT USING THIRD VARIABLES:-

#include

int main()
{
int a,b;
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("After Swap a=%d\tb=%d",a,b);

}

INPUT:-

42
28

OUTPUT:-

a=28
b=42

Previous Post
Next Post