You are on page 1of 8

1.

Swap two number using third varible

#include <iostream>

using namespace std;

int main()

int a = 25, b = 39, c;

cout << "Before swapping." << endl;

cout << "a = " << a << ", b = " << b << endl;

c = a;

a = b;

b = c;

cout << "\nAfter swapping." << endl;

cout << "a = " << a << ", b = " << b << endl;

return 0;

Output :
2. Area and perimeter of rectangle

#include <iostream>

using namespace std;

int main()

int length,area,peri,width;

cout << "\n enter a length of rectangle" << endl;

cin>>length;

cout<<" \n enter a width of rectangle"<<endl;

cin>>width;

area=(length*width);

peri=2*(length*width);

cout<<"\n area of rectangle "<<area;

cout<<"\n perimeter of rectangle "<<peri;

return 0;

}
3.

#include<iostream>

using namespace std;

int main(){

int num1;

cout<< "enter a value of num1";

cin>>num1;

if(num1 > 0)

cout << " The entered number is positive.\n\n";

else if(num1 < 0)

cout << " The entered number is negative.\n\n";

}
else

cout << " The number is zero.\n\n";

return 0;

Output:

4.

#include<iostream>

using namespace std;

int main(){

int num1;

cout<< "enter a value of num1";


cin>>num1;

for (int i = 1; i <=10 ; i++)

cout << num1 << " * " << i << " = " << num1 * i << endl;

return 0;

Output:

5.

#include<iostream>

using namespace std;

int main(){

int a=25, b=20;

cout<<"before swapping: \n"<<endl;

cout<<"a="<<a<<"b="<<b<<endl;

a=a+b;

b=a-b;

a=b-a;

cout<<"\n after swapping: \n"<<endl;


cout<<"a="<<a<<"b="<<b<<endl;

return 0;

Output:

6.

#include<iostream>

using namespace std;

int main()

float km, met,cent;

cout << "\n\n Convert centimeter into meter and kilometer :\n";

cout << "--------------------------------------------------\n";

cout << " Input the distance in centimeter : ";

cin >> cent;

met = (cent/100);

km = (cent/100000);

cout << " The distance in meter is: "<< met << endl;

cout << " The distance in kilometer is: "<< km << endl;

cout << endl;

return 0;

}
Output:

7.

#include<iostream>

using namespace std;

int main()

int p,r,t,i;

cout << "\n\n Calculate the Simple Interest :\n";

cout << " -----------------------------------\n";

cout<<" Input the Principle: ";

cin>>p;

cout<<" Input the Rate of Interest: ";

cin>>r;

cout<<" Input the Time: ";

cin>>t;

i=(p*r*t)/100;

cout<<" The Simple interest for the amount "<<p<<" for "<<t<<" years @
"<<r<<" % is: "<<i;

cout << endl;

return 0;

}
Output:

8.

You might also like