Notification texts go here Contact Us Click here

Using C program to add two number's .

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated


 

➤  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

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.