//Program to receive two integer numbers and display their sum
#include <iostream>
using namespace std; int main()
{
int num1, num2, sum;
//variables num1, num2, and sum are declared as integers
cout << "\n Enter Number 1: ";
cin >> num1;
cout << "\n Enter Number 2: "; cin >> num2;
sum = num1 + num2;
cout << "\n The sum of " << num1 << " and " << num2 << " is " << sum;
}
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "\n Enter a character: ";
cin >> ch;
ch = ch + 1;
cout << "\n The Next character: " << ch;
}
Enter a character: A
The Next character: B
#include <iostream>
using namespace std;
int main ()
{
int n;
char ch;
cout << "\n Enter an ASCII code (0 to 255): ";
cin >> n;
ch = n;
cout << "\n Equivalent Character: " << ch;
}
Enter an ASCII code (0 to 255): 100
Equivalent Character: d
#include <iostream>
using namespace std;
int main()
{
float r, area;
cout << "\n Enter Radius: ";
cin >> r;
area = 3.14 * r * r;
cout << "\n The Area of the circle is " << area;
}
Enter Radius: 6.5
The Area of the circle is 132.665
#include <iostream>
using namespace std;
int main()
{
short a;
nsigned short b;
signed short c;
int d;
unsigned int e;
signed int f;
long g;
unsigned long h;
signed long i;
char j;
unsigned char k;
signed char l;
float m;
double n;
long double p;
cout << "\n Size of short = " << sizeof(a);
cout << "\n Size of unsigned short = " << sizeof(b);
cout << "\n Size of signed short = " << sizeof (c);
cout << "\n Size of int = " << sizeof(d);
cout << "\n Size of unsigned int = " << sizeof(e);
cout << "\n Size of signed int = " << sizeof(f);
cout << "\n Size of long = " << sizeof(g);
cout << "\n Size of unsigned long = " << sizeof(h);
cout << "\n Size of signed long = " << sizeof(i);
cout << "\n Size of char = " << sizeof(j);
cout << "\n Size of unsigned char = " << sizeof(k);
cout << "\n Size of signed char = " << sizeof(l);
cout << "\n Size of float = " << sizeof(m);
cout << "\n Size of double = " << sizeof(n);
cout << "\n Size of long double = " << sizeof(p);
}
Size of short = 2
Size of unsigned short = 2
Size of signed short = 2
Size of int = 4
Size of unsigned int = 4
Size of signed int = 4
Size of long = 4
Size of unsigned long = 4
Size of signed long = 4
Size of char = 1
Size of unsigned char = 1
Size of signed char = 1
Size of float = 4
Size of double = 8
Size of long double = 12
#include <iostream>
using namespace std;
int main()
{
float pi = 3.14, radius, height, CSA;
cout << "\n Curved Surface Area of a cylinder";
cout << "\n Enter Radius (in cm): ";
cin >> radius;
cout << "\n Enter Height (in cm): ";
cin >> height;
CSA = (2*pi*radius)*height;
system("cls");
cout << "\n Radius: " << radius <<"cm";
cout << "\n Height: " << height << "cm";
cout << "\n Curved Surface Area of a Cylinder is " << CSA <<" sq. cm.";
}
Curved Surface Area of a cylinder
Enter Radius (in cm): 7
Enter Height (in cm): 20
Radius: 7cm
Height: 20cm
Curved Surface Area of a Cylinder is 879.2 sq. cm.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout << "\n Enter number 1: ";
cin >> num1;
cout << "\n Enter number 2: ";
cin >> num2;
int sum = num1 + num2; // Dynamic initialization
cout << "\n Average: " << sum /2;
}
Enter number 1: 78
Enter number 2: 65
Average: 71
#include <iostream>
using namespace std;
int main()
{
int radius;
float pi = 3.14;
cout << "\n Enter Radius (in cm): ";
cin >> radius;
float perimeter = (pi+2)*radius; // dynamic initialization
float area = (pi*radius*radius)/2; // dynamic initialization
cout << "\n Perimeter of the semicircle is " << perimeter << " cm";
cout << "\n Area of the semicircle is " << area << " sq.cm";
}
Enter Radius (in cm): 14
Perimeter of the semicircle is 71.96 cm
Area of the semicircle is 307.72 sq.cm
#include <iostream>
using namespace std;
int main()
{
int num;
int &temp = num; //declaration of a reference variable temp
num = 100;
cout << "\n The value of num = " << num;
cout << "\n The value of temp = " << temp;
}
The value of num = 100
The value of temp = 100
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float basic, da, hra, gpf, tax, gross, np;
char name[30];
cout << "\n Enter Basic Pay: ";
cin >> basic;
cout << "\n Enter D.A : ";
cin >> da;
cout << "\n Enter H.R.A: ";
cin >> hra;
gross = basic+da+hra; // sum of basic, da nad hra
gpf = (basic+da) * 0.10; // 10% 0f basic and da
tax = gross * 0.10; //10% of gross pay
np = gross - (gpf+tax); //netpay = earnings - deductions
cout << setw(25) << "Basic Pay : " << setw(10)<< basic<< endl;
cout << setw(25) << "Dearness Allowance : "<< setw(10)<<da<< endl;
cout<<setw(25)<<"House Rent Allowance : "<<setw(10)<< hra<<endl;
cout << setw(25) << "Gross Pay : " << setw(10) << gross << endl;
cout << setw(25) << "G.P.F : " << setw(10) << gpf << endl;
cout << setw(25) << "Income Tax : " << setw(10)<< tax << endl;
cout << setw(25) << "Net Pay : " << setw(10) << np << endl;
}
Enter Basic Pay: 12000
Enter D.A : 1250
Enter H.R.A : 1450
Basic Pay : 12000
Dearness Allowance : 1250
House Rent Allowance : 1450
Gross Pay : 14700
G.P.F : 1325
Income Tax : 1470
Net Pay : 11905
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float hra = 1200.123;
cout << setprecision (5) << hra;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout.setf(ios::fixed);
cout << setprecision(2)<<0.1;
}
#include <iostream>
using namespace std;
int main()
{
int a=6;
float b=3.14;
cout << a+b;
}
#include <iostream>
using namespace std;
int main( )
{
float varf=78.685;
cout << (int) varf;
}
#include <iostream>
using namespace std;
int main()
{
double varf=178.25255685;
cout << (float) varf << endl;
cout << (int) varf << endl;
}
178.253
178
#include <iostream>
using namespace std;
int main()
{
int m1, m2, m3, sum;
cout << "\n Enter Mark 1: ";
cin >> m1;
cout << "\n Enter Mark 2: ";
cin >> m2;
cout << "\n Enter Mark 3: ";
cin >> m3;
sum = m1 + m2 + m3;
cout << "\n The sum = " << sum;
}
Make changes in the above code to get the average of all the given marks.
#include <iostream>
using namespace std;
int main()
{
int radius;
float area;
cout << "\n Enter Radius: ";
cin >> radius;
area = 3.14 * radius * radius;
cout << "\n The area of circle = " << area;
}
#include <iostream>
Using namespace std;
int main( )
{
cout << “Enter a value ”;
cin << num1 >> num2
num+num2=sum;
cout >> “\n The Sum= ” >> sum;
}
#include <iostream>
using namespace std;
int main()
{
int h=10; w=12;
cout << "Area of rectangle " << h+w;
}
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.