Showing posts with label Two. Show all posts
Showing posts with label Two. Show all posts

Monday, 22 April 2013

Addition and Multiplication of Two Numbers

Description:

In c++ 'goto' operator is used to repeat program again. In other words it acts as infinite loop.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c,d;
    xy:
    cout<<"Enter two numbers to get their sum and product"<<endl;
    cout<<"Enter the value of a"<<endl;
    cin>>a;
    cout<<"You have entered a="<<a;
    cout<<endl<<"Enter the value of b"<<endl;
    cin>>b;
    cout<<"You have entered b="<<b<<endl;
    c=a+b;
    cout<<"The sum of a and b is"<<endl<<"a+b="<<c<<endl;
    d=a*b;
    cout<<"The product of a and b is"<<endl<<"a*b="<<d<<endl;
    goto xy;
    getche();
    return 0;
    }


Output:


Taking two inputs in variables and then interchanging their values

Description:

In c++, to take inputs from user 'cin' operator is used and to show output 'cout' operator is used.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"Enter value of A"<<endl;
    cin>>a;
    cout<<endl;
    cout<<"Enter value of B"<<endl;
    cin>>b;
    c=a;
    a=b;
    b=c;
    cout<<"interchanged values are"<<endl;
    cout<<a<<endl<<b<<endl<<"ok";
    getche();
    return 0;
    }


Output: