➤ Program to add two numbers .
#include<stdio.h>
int main()
{ int a,b;
a=19;
b=35;
printf("Sum of %d and %d is = %d",a,b,a+b);
return 0;
}
OUTPUT :
Sum of 19 and 35 is = 54
➤ Program to add numbers by accepting input from user input .
#include<stdio.h>
int main()
{
int a,b,sum;
printf("Enter two numbers: ");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum of %d and %d is = %d",a,b,sum);
return 0;
}
OUTPUT :
Enter two numbers: 4 6
sum of 4 and 6 is = 10
➤ Program to add numbers from 1 to n using while loop .
#include<stdio.h>
int main()
{ int i=1,n,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
sum=sum+i;
i++;
}
printf("The sum of %d numbers is :%d",n,sum);
return 0;
}
//#while_loop
OUTPUT :
Enter the value of n: 6
The sum of 6 numbers is :21
Enter the value of n: 8
The sum of 8 numbers is :36