Addition of two numbers in C - using scanf and assaiment operator | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Thursday, June 13, 2019

Addition of two numbers in C - using scanf and assaiment operator | My CS Tutorial

C program-addition of two numbers

In this tutorial we will learn that how a C program add two or more numbers.


C program - using assaiment operator

#include<stdio.h>
#include<conio.h>
void main()
{
int num1;
int num2;
int sum;
clrscr();

num1=25;
num2=65;

sum=num1+num2;

printf("\n The addition of two numbers is=");
printf("%d",sum);

getch();
}

Output:





C program - using scanf function


#include<stdio.h>
#include<conio.h>
void main()
{
int num1;
int num2;
int sum;
clrscr();

printf("\n Enter the value of first number=");
scanf("%d",&num1);

printf("\n Enter the value of second number=");
scanf("%d",&num2);

sum=num1+num2;

printf("\n The addition of two numbers is=");
printf("%d",sum);
getch();

}


Output:


No comments:

Post a Comment