Program to assign values of two numbers and print their addition.

Program to assign values of two numbers and print their addition

In this program we will learn how we can add two digits using C programming, for this we will first get the user to input two numbers and then add them using the + operator.

1. Program to assign values of two numbers and print their addition?

Program

#include<stdio.h>

#include<conio.h>

void main()

{

  int a=10,b=20;

    clrscr();       //Devc++ compiler does not use clrscr.

  int ans = a + b;

  printf("Addition is : %d",ans);

  getch();

  }

Output

Addition is : 30

2. Program to accept values of two numbers and print their addition.

Program

#include<stdio.h>

#include<conio.h>



void main()

{

  int a,b,ans;

    clrscr();         //Devc++ compiler does not use clrscr.

  printf("Enter 1st number:");

    scanf("%d",&a);

  printf("Enter 2nd number:");

    scanf("%d",&b);

  ans = a + b;

  printf("Addition is : %d",ans);

  getch();

  }

Output

Enter 1st number:52
Enter 2nd number:79
Addition is : 131

Similarly, you can practice programs on our website, here you are taught to make programs in a simple and easy way.

Learn More:- c program to print Hello world

Previous articleTypescript tutorial in Hindi -Sirfpadhai
Next articleleap year condition in Hindi |Write a program in C to check given no is a leap year or not in Hindi

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here