Basic C++ Programs Using Arithmatic Operators
By hotshotracer, 30th Jun 2012 | Follow this author
| RSS Feed | Short URL http://nut.bz/25u0t6da/
Posted in WikinutBusinessIT & Ecommerce
Do you know how to write computer programs? If you not know, just look through some basic C++ programs using arithmetic operators such as addition(+), subtraction(-), Multiplication(*), division(/) and fractional part etc. This article also contains download link of free software that used for running C++ programs in computer.
- C++ Program for Arithmatic Addtion Operation
- C++ Program for Arithmatic Subtraction Operation
- C++ Program for Arithmatic Multiplication Operation
- C++ Program for Arithmatic Division Operation
- C++ Program for Arithmatic Fraction Operation
C++ Program for Arithmatic Addtion Operation
This is a program of C++ for finding sum of any two numbers. Here float is used, so we can find any two fractional numbers sum by using addition operation. It is a simple program for finding sum of any two numbers. This program can be run into any C++ programming software like Microsoft Visual C++, Borland etc. If you don't have a C++ programming software Download now.
Program
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,sum;
cout<<"Enter first number: "<<endl;
cin>>a;
cout<<"Enter second number: "<<endl;
cin>>b;
sum=a+b;
cout<<"sum = "<<sum<<endl;
getch();
}
Output
Enter first number: 2
Enter second number:5
Sum=7
C++ Program for Arithmatic Subtraction Operation
This is a C++ program for subtracting any two numbers. For subtraction negative sign (-) is used. In this program always enter "a>b".
Program
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,Result;
cout<<"Enter first number: "<<endl;
cin>>a;
cout<<"Enter second number: "<<endl;
cin>>b;
Result=a-b;
cout<<"Result = "<<Result<<endl;
getch();
}
Output
Enter first number: 6
Enter second number:4
Result=2
C++ Program for Arithmatic Multiplication Operation
This is a program for finding product of two numbers. For finding product multiplication operator(*) is used.
Program
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,Result;
cout<<"Enter first number: "<<endl;
cin>>a;
cout<<"Enter second number: "<<endl;
cin>>b;
Result=a*b;
cout<<"Result = "<<Result<<endl;
getch();
}
Output
Enter first number: 6
Enter second number:4
Result=24
C++ Program for Arithmatic Division Operation
This program for arithmatic operation called division. For division, division operator(/) is used. Here "b" is not equal to zero. If you give zero program will shows error or it closes immediately.
Program
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,Result;
cout<<"Enter first number: "<<endl;
cin>>a;
cout<<"Enter second number: "<<endl;
cin>>b;
Result=a/b;
cout<<"Result = "<<Result<<endl;
getch();
}
Output
Enter first number: 6
Enter second number:4
Result=1.5000
C++ Program for Arithmatic Fraction Operation
This is a program for finding fraction of two numbers. For finding fraction, arithmatic operator percentage sign (%) is used.
Program
#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,Result;
cout<<"Enter first number: "<<endl;
cin>>a;
cout<<"Enter second number: "<<endl;
cin>>b;
Result=a%b;
cout<<"Result = "<<Result<<endl;
getch();
}

Comments