Addition of two number in c

Addition of two number in c 
  
        In these tutorial we introduce some more predefine function and logical operators.




#include<stdio.h>
#include<conio.h> 
void main ()
{
   int a, b, ans;
   clrscr();
   printf("Enter two number for addition:");
   scanf("%d%d",&a, &b);
   ans=a+b;
   printf("\nThe addition of %d and %d is %d",a, b, ans);
   getch();
}
 Output:
Enter two number for addition:5
7 
The addition of 5 and 7 is 12


Explanation:- 

 int is a integer data type. In C language there are many data types are available.
  1. int - integer: a whole number.
  2. float - floating point value: i.e a number with a fractional part.
  3. double - a double-precision floating point value.
  4. char - a single character.
  5. void - valueless special purpose type which we will examine closely in later sections.
int a, b, ans are variables is declared in int data type i.e they store only whole number.(Instead of a b ans you can use any other variable that you want).

clrscr() is a predefine function use to clear screen to give new output.(this function is work in turbo C).

scanf() is a predefine function use to assign value in declared variable given by user. example in output section user type 5 and 7 this value is store in a and b. %d%d &a and &b that means first enter value stored in a variable and second entered value in b variable.

ans=a+b this is a logic of addition i.e add value of a is 5 and value of b is 7.
addition of a and b is stored in ans variable.
For subtraction use -, for multiplication use *, for division use / and for modular division use % .(Try yourself a/b, a-b, a*b, a%b)
This operators called logical operators.


%d and %d is %d",a, b, ans in this line in first %d print value of a and second %d print value of b and third %d print value of ans.

If any query or doubt comment below.... 






Key note:- /* */ is use to comment the line in program.

No comments

Powered by Blogger.