Showing posts with label for. Show all posts
Showing posts with label for. Show all posts

Monday, 22 April 2013

Code for Simple Calculator

Description:

This program perform different operation of calculator.

Code:


#include<iostream>
#include<conio.h>
using namespace std;
int sum(int,int);
int difference(int,int);
int multiplication(int,int);
float division(int,int);
int average(int,int);
int s=0,d=0,m=0,g=0;float v=0;
int main()
{
   int a,b;
cout<<"enter first number"<<endl;
 cin>>a
cout<<"enter second number"<<endl;
cin>>b;
 s= sum (a,b);
 cout<<s<<endl;
 d= difference (a,b);
 cout<<d<<endl;
 m= multiplication (a,b);
 cout<<m<<endl;
 v= division (a,b);
 cout<<v<<endl;
 g= average (a,b);
 cout<<g<<endl;
 cout<<"ok";
getche();
return 0;
}
int sum (int x,int y)
{
 s=x+y;
 cout<<"sum="<<endl;
return s;
}
int difference (int x,int y)
{
d=x-y;
cout<<"difference="<<endl;
return d;
}
int multiplication (int x,int y)
{
m=x*y;
cout<<"multiplication="<<endl;
return m;
}
float division (int x,int y)
{
v=x/y;
cout<<"division="<<endl;
return v;
}
int average (int x,int y)
{
g=(x+y)/2;
cout<<"average="<<endl;
return g;
}


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: