Thursday 14 March 2013

Calculate the sum of two given numbers.


Statement:
Calculate the sum of two given numbers.



ü    Algorithm:

                                                Step 1: Read a 
                                                Step 2: Read b
                                                Step 3: c=a+b
                                                Step 4: print c
                                                Step 5: End



v Program Listing:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Please enter a number:");
scanf("%d",&a);
printf("\nPlease enter another number:");
scanf("%d",&b);
c=a+b;
printf("\nThe sum of two number is:%d",c);
getch();
}



·   Output:
Please enter a number: 42
Please enter another number: 56
The sum of two number is:98

§  Discursion:
                                                I.            It works properly.
                                              II.            We can made the sum of more than two numbers similarly.
                                            III.            Since we use short signed int so it works within the number range  -32768  to +32767
                                           IV.            If we use long int then it works within the number range                    -2147483648  to  +2147483647

No comments:

Post a Comment