Saturday, 3 March 2012

Addition of two numbers in c++

Hi,

In this post i am going to brief you about calculating addition of two numbers in C++.

Recall the last program which we done in previous post and edit it like this...

---------------

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,sum;
clrscr();
cout<<"Enter First Number :";
cin>>a;
cout<<"Enter Second Number : ";
cin>>b;
sum=a+b;
cout<<"Sum :";
cout<<sum;
getch();
}
---------------

In this program  i declared one more variable as int (sum)  to store the sum value of the a & b. after reading the input from keyboard I declared a function -   sum=a+b;    - that generates (a+b) the result and store it to the variable "sum". Then "sum" printed on screen.

hope you understood it well.

Screenshot 1

Screenshot 2



Exercise
  1. Subtraction / multiplication / division with three numbers.(read &print) -
  2. Write a program to input a radius and print the  Area Of a circle .

  3. Write a program to input marks of  five subjects and print student name and his average.


0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Web Hosting Coupons