Q:

C Program for Addition of Two Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program for Addition of Two Numbers (Simple Way)
  • C Program for Addition of Two Numbers Using Function
  • C Program tfor Addition of Two Numbers Using Array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program for Addition of Two Numbers (Simple Way)

To get the Addition of two numbers, we have to first take two numbers from the user, then calculate these numbers to find the sum.

formula to calculate the Addition of two numbers

Sum = a+b;

Algorithm

  • Program Start
  • Declaring Variables (x,y,sum)
  • Input Two Numbers
  • Calculating Sum of Two Numbers
  • Displaying the Sum of Two Numbers
  • Program End

Program

//C Program for Addition of Two Numbers (Simple Way)

#include<stdio.h>
void main()
{
  //Declaring three Variables
     int x, y, sum;           

 //Input  Numbers
   printf("Enter Two Numbers : \n");    
   scanf("%d %d",&x, &y);     

  //Calculating Sum of Two numbers
   sum = x + y ;

//Desplaying Sum
   printf("Sum is : %d", sum);    

}

Output:

Enter Two Numbers :
2
9
Sum is : 11

C Program to Find the Sum of Two Numbers Using Function

Algorithm

  • Program Start
  • Declaring variables
  • Input two Number
  • Calling Function to calculate Sum of Two Numbers
  • Print the Sum of two Numbers
  • Program End

Program

//C Program to Find the Sum of Two Numbers Using Function

#include<stdio.h>
int sum(int, int);
int main()
{
 //Declaring Variables
   int x, y, s;

  //Input two Numbers From User
   printf("Enter Two Numbers : \n");
   scanf("%d %d",&x, &y);

 //Calling Function to find the Sum of two numbers
   s = sum(x,y);
   
  printf("Sum is : %d \n", s);

   return 0;
}
int sum(int a, int b)
{
    return (a+b);
}

Output

Enter Two Numbers :
32
81
Sum is : 113

C Program to Find the Sum of Two Numbers Using Array

Algorithm

  • Program Start
  • Declaring variables (sum , a[2])
  • Input two Numbers From the User
  • Calculating Sum
  • Display the Sum of two Numbers
  • Program End

Program

//C Program to Find the Sum of Two Numbers Using Array

#include<stdio.h>
int main()
{
  //Declaring  Variables

   int i, sum = 0, a[2];

//Input Numbers
   printf("Enter Two Numbers : \n");
   for(i=0; i<2; i++)
   {
    scanf("%d",&a[i]);
   }

//Calculating Sum
   for(i=0; i<2;i++)
   {
    sum = sum + a[i];
   }
   printf("Sum is : %d", sum);

 return 0;
}

Output

Enter Two Numbers :
23
75

Sum is : 98

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to Find Sum of n Natural Numbers... >>
<< C Program To Find Sum of N Numbers...