Sunday, October 30, 2022

C++ Problem (10) : How to show that a number entered by user is an even or odd?

 C++ (10) : How to show that a number entered by user is an even or odd?

Code:

#include<iostream>
using namespace std;
int main(){
long int n;
cout<<"****Finding even and odd number.****"<<endl;
cout<<"Enter a number."<<endl;
cin>>n;

if( n% 2==0){
cout<<"You entered an even number."<<endl;
}
else
cout<<"You entered an odd number."<<endl;
return 0;
}

Output:

****Finding even and odd number.****
Enter a number.
56987231
You entered an odd number.

Wednesday, October 26, 2022

C++ Problem (9) : How to swap two numbers without using third variable?

 C++  (9) : How to swap two numbers without using third variable?

#include<iostream>
using namespace std;
int main(){
double a,b;
cout<<"*****Swapping two numbers without using third variable.*****"<<endl;
cout<<"Enter first number."<<endl;
cin>>a;

cout<<"Enter second number."<<endl;
cin>>b;

cout<<"Before swapping:"<<endl;
        cout<<"a = "<<a<<endl;
        cout<<"b = "<<b<<endl;

       a=a+b;
       b=a-b;
       a=a-b;

cout<<"After swapping:"<<endl;
        cout<<"a = "<<a<<endl;
        cout<<"b = "<<b<<endl;
return 0;
}

Output:

*****Swapping two numbers without using third variable.*****
Enter first number.
10
Enter second number.
5
Before swapping:
a = 10
b = 5
After swapping:
a = 5
b = 10

Tuesday, October 25, 2022

C++ Problem (8) : How to swap two numbers? Using third variable.

C++  (8) : How to swap two numbers? Using third variable.

Code:

#include<iostream>
using namespace std;
int main(){
double a,b,c;
cout<<"*****Swapping two numbers using third variable.*****"<<endl;
cout<<"Enter first number."<<endl;
cin>>a;
cout<<"Enter second number."<<endl;
cin>>b;
cout<<"The given numbers are:"<<endl;
    cout<<"a = "<<a<<endl;
    cout<<"b = "<<b<<endl;
    c=a;
    a=b;
    b=c;

cout<<"The numbers after swapping."<<endl;
    cout<<"a = "<<a<<endl;
    cout<<"b = "<<b<<endl;
return 0;
}

Output:

*****Swapping two numbers using third variable.*****
Enter first number.
10
Enter second number.
5
The given numbers are:
a = 10
b = 5
The numbers after swapping.
a = 5
b = 10

Monday, October 24, 2022

C++ Problem (7) : How to find the surface area of a cylinder when radius and height of the cylinder are given?

 C++ (7) : How to find the surface area of a cylinder when radius and height of the cylinder are given?

Code:

#include<iostream>
using namespace std;
int main(){
double r,h,a;
cout<<"*****Finding the surface area of a Cylinder.*****"<<endl;

cout<<"Enter the radius."<<endl;
cin>>r;

cout<<"Enter the height."<<endl;
cin>>h;

         a= 2*3.14*r*h+2*3.14*r;

cout<<"The surface area of cylinder having radius "<<r<<" and height "<<h<<"  approximately : "<<a<<endl;
return 0;
}

Output:

*****Finding the surface area of a Cylinder.*****
Enter the radius.
1
Enter the height.
1
The surface area of cylinder having radius 1 and height 1 approximately : 12.56

C++ Problem (6) : How to find the area of triangle while base and hight of the triangle are given?

 C++: (6) : How to find the area of a triangle while base and hight of the triangle are given?

Code:

#include<iostream>
using namespace std;
int main(){
double b,h,a;
cout<<"*****Finding the area of a Triangle.*****"<<endl;
cout<<"Enter the base."<<endl;
cin>>b;

cout<<"Enter the height."<<endl;
cin>>h;

       a= (b*h)/2;

cout<<"The area of triangle having base "<<b<<" and height "<<h<<" is: "<<a<<endl;
return 0;
}

OutPut:

*****Finding the area of a Triangle.*****
Enter the base.
5
Enter the height.
10
The area of triangle having base 5 and height 10 is: 25

C++ Problem (5) : How to find the area of a rectangle when length and width are given?

C++ :Problem (5) : How to find the area of a rectangle when length and width are given?


Code:

#include<iostream>
using namespace std;
int main(){
double l,w,a;

cout<<"*****Finding the area of  a rectangle.*****"<<endl;
cout<<"Enter the length."<<endl;
cin>>l;

cout<<"Enter the width."<<endl;
cin>>w;

        a= l*w;

cout<<"The area of rectangle having length "<<l<<" and width "<<w<<" is: "<<a<<endl;
return 0;
}

Output:

*****Finding the area of a rectangle.*****
Enter the length.
12
Enter the width.
6
The area of rectangle having length 12 and width 6 is: 72

Thursday, October 20, 2022

C++ Problem (4) : How to find the circumference of a circle when its radius is given i,e user will input the radius?

 C++:

(4) : How to find the circumference of a circle when its radius is given i,e user will input the radius?

Code:

#include<iostream>
using namespace std;
int main(){

double c,r;
cout<<"*****Finding the circumference of a circle.*****"<<endl;
cout<<"Enter the radius of the circle."<<endl;
cin>>r;

        c= 2*3.14*r;

cout<<"The circumference of the circle having radius "<<r<<" is: "<<c<<endl;
return 0;
}

Output:

*****Finding the circumference of a circle.*****
Enter the radius of the circle.
2
The circumference of the circle having radius 2 is: 12.56

C++ Problem (3): How to find the distance covered by a car when average speed and time is given i,e user will input the speed and time?

 C++:

(3): How to find the distance covered by a car when average speed and time is given i,e user will input the speed and time?

Code:

#include<iostream>
using namespace std;
int main(){

double v,t,s;
cout<<"*****Finding the distance covered by a car.*****"<<endl;
cout<<"Enter average speed of the car."<<endl;
cin>>v;

cout<<"Enter time taken by the car."<<endl;
cin>>t;

        s= v*t;

cout<<"The distance covered by the car  is: "<<s<<endl;
return 0;
}

Output:

*****Finding the distance covered by a car.*****
Enter average speed of the car.
10
Enter time taken by the car.
5
The distance covered by the car  is: 50

C++ Problem (2): How to calculate area of a circle when radius is given i,e inputs the radius from user?

 C++:

(2): How to calculate area of a circle when radius is given i,e inputs the radius from user?

Code:

#include<iostream>
using namespace std;
int main(){

double r, area;

cout<<"*****Calculating the area of a circle*****"<<endl;
cout<<"Enter  radius of the circle."<<endl;

cin>>r;

       area= 3.14*r*r;

cout<<"The area of the circle having radius "<<r<<" is: "<<area<<endl;
return 0;
}

Output:

*****Calculating the area of a circle*****
Enter  radius of the circle.
2
The area of the circle having radius 2 is: 12.56




C++ Problem (1): How to add two numbers, inputs from user and to display the result to the user?

C++:

(1):How to add two numbers, inputs from user and to display the result to the user?

Code:

#include<iostream>
using namespace std;
int main(){

int x,y,sum;

cout<<"*****Adding two numbers*****"<<endl;

cout<<"Enter First Number."<<endl;

cin>>x;

cout<<"Enter Second Number."<<endl;

cin>>y;

sum=x+y;

cout<<"The Sum of two numbers is "<<sum<<endl;

return 0;

Output:

*****Adding two numbers*****
Enter First Number.
123
Enter Second Number.
321
The Sum of two numbers is 444

 How to create a shortcut for a program(application) on windows? Fisrt of all if you are at desktop screen, click right on mouse and click o...