C Program To Find Sum of Two Numbers
C Program To Find Sum of Two Numbers
#include<stdio.h>
int main() {
int a, b, sum;
sum = a + b;
return(0);
}
C++ Program to find sum of two
numbers
#include <iostream>
using namespace std;
int main()
{
//Declaring two integer variables
int num1, num2;
/* cout displays the string provided in the
*double quotes as it is on the screen
*/
cout<<"Enter first integer number: ";
/* cin is used to capture the user input
and assign it to the variable.
*/
cin>>num1;
cout<<"Enter second integer number: ";
cin>>num2;
cout<<"Sum of entered numbers is: "<<(num1+num2);
return 0;
}
Algorithm of the sum of two numbers
• Step 1: Start
• Step 2: Declare variables
num1, num2 and sum.
• Step 3: Read values for
num1, num2.
• Step 4: Add num1 and
num2 and assign the
result to a variable sum.
• Step 5: Display sum
• Step 6: Stop
Algorithms
Algorithm is a step-by-step procedure,
which defines a set of instructions to be
executed in a certain order to get the
desired output. Algorithms are generally
created independent of underlying
languages, i.e. an algorithm can be
implemented in more than one
programming language.
From the data structure point of view, following are
some important categories of algorithms :
• Problem definition
• Development of a model
• Specification of an Algorithm
• Designing an Algorithm
• Checking the correctness of an Algorithm
• Analysis of an Algorithm
• Implementation of an Algorithm
• Program testing
• Documentation
An Algorithm Development
Process
Step 1: Obtain a description of the problem.
Step 2: Analyze the problem.
Step 3: Develop a high-level algorithm.
Step 4: Refine the algorithm by adding
more detail.
Step 5: Review the algorithm.
Algorithm Analysis
Efficiency of an algorithm can be analyzed at two different stages, before
implementation and after implementation. They are the following −
• A fixed part that is a space required to store certain data and variables, that
are independent of the size of the problem. For example, simple variables
and constants used, program size, etc.
Algorithm: SUM(A, B)
Step 1 - START
Step 2 - C ← A + B + 10
Step 3 - Stop