LOOSE TECH - C Programming Blog Online
Thursday, 15 August 2013
How To Perform Addition In C Language
//Program to perform addition in 'C' with explanation
1. #include
2. #include
3. void main() 4. { 5. int a,b,c; 6. clrscr(); 7. printf("Enter a number\n"); 8. scanf("%d",&a); 9. printf("\nEnter a second number\n"); 10. scanf("%d",&b); 11. c=a+b; 12. printf("\nAddition is: %d",c); 13. getch(); 14. } /* OUTPUT Enter a number 7 Enter a second number 2 Addition is: 9 */
Explanation:-
In this Program, we used some terms that are used in almost every program of C.
Let understand the meaning of these terms.
1.
int a,b,c;
int
→
Is a Integer data type whose range depends upon the compiler.
For a 16-bit compiler like Turbo C or Turbo C++ the range is -32768 to +32767.
For a 32-bit compiler like visual studio or gcc the range is -2147483648 to +2147483647.
a
→
Is a variable of Integer type used to store an integer constant.
b
→
Is a variable of Integer type used to store an integer constant.
c
→
Is a variable of Integer type used to store an integer constant.
Variable:-
An entity (it can be anything which exists in real world) that may vary during program execution is known as variable.
Variable names are the names given to locations in memory.
a,b,c
→
Commas between variables are used to define two or more variables in a line. Otherwise, We have to write it like this:
int a;
int b;
int c;
2.
scanf("%d",&a);
scanf()
→
Is used to read input from the user.
%d
→
Defines that input is of integer type.
&a
→
Defines that input is stored in variable 'a'.
3.
c=a+b;
c=a+b
→
This statement add the value of two variables 'a' and 'b'.
'+' perform addition.
'==' used to store the addition in another variable called 'c'.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.