A PRACTICAL RECORD ON
PROGRAMMING IN C ++ LANGUAGE
SUBMITTED BY:-
PURNA CHANDRA BAUG
ROLL NUMBER :- 11801N241019
PAPER :- MATH-205
[Link]. 2ND SEMESTER MATHEMATICS (2024 – 2026)
DEPARTMENT OF MATHEMATICS
MAHARAJA SRIRAM CHANDRA BHANJA
DEO UNIVERSITY, TAKATPUR, BARIPADA
[Link] a c++ program to display your name in screen.
#include<iostream>
#include<string>
using namespace std;
int main()
char name[20];
cout<<"Enter your name ";
cin>>name;
cout<<"Your name is "<name;
Return 0;
OUTPUT
Enter your name PURNA
Your name is PURNA
[Link] a c++ program to input two numbers from the user and display
them.
#include<iostream>
using namespace std;
int main()
int x,y;
cout<<"Enter any two numbers \n";
cin>>x>>y;
cout<<"Entered numbers are: ";
cout<<x<<”\t”<<y;
return 0;
OUTPUT
Enter any two numbers
20
30
Entered numbers are: 20 30
[Link] a c++ program to display data using cout statement.
#include<iostream>
using namespace std;
int main()
cout << "========" << endl;
cout << "\n";
cout << 123 << endl;
cout << 3.145 << endl;
cout << "Number\t" << 452 << endl;
cout<<"\n==THE END==" << endl;
return 0;
OUTPUT
123
3.145
Number 452
==THE END==
[Link] a c++ program to find the area of circle.
#include
using namespace std;
int main()
int r;
float area;
cout<<"Enter radious ";
cin>>r;
area=3.14*r*r;
cout<<"\nArea of the circle is "<<area;
return 0;
OUTPUT
Enter radious 10
Area of the circle is 314
[Link] a c++ program to calculate the length of a string.
#include<iostream>
#include<string>
using namespace std;
int main()
char name[20];
int len;
cout<<" Enter your name:\t";
cin>>name;
len=strlen(name);
cout<<" The length of the string is "<<len;
return 0;
OUTPUT
Enter your name: PURNACHANDRA
The length of the string is 12
[Link] a find average of two number.
#include<iostream>
using namespace std;
int main()
float x,y,sum,avg;
cout<<"Enter two numbers\n";
cin>>x;
cin>>y;
sum=x+y;
avg=sum/2;
cout<<"Sum of the two numbers is "<<sum;
cout<<"\nAverage of the two numbers is "<<avg;
return 0;
OUTPUT
Enter two numbers
20
40
Sum of the two numbers is 60
Average of the two numbers is 30
[Link] a c++ program to check whether a number is even or odd.
#include<iostream>
using namespace std;
int main()
int x;
cout<<"Enter a number=";
cin>>x;
if(x%2==0)
goto even;
else
goto odd;
even:cout<<x<<" is even number ";
odd:cout<<x<<" is odd number ";
return 0;
OUTPUT
Enter a number=31
31 is odd number
[Link] a c++ program to display all leapyears from 1900 to 2002.
#include<iostream>
using namespace std;
int main()
int x;
cout<<"\nAll the years between 1900 to 2002 are\n";
for(x=1900;x<=2002;x++)
if((x%4==0&&x%100!=0)||(x%100==0&&x%400==0))
cout<<x<<" is a Leap year\n";
return 0;
OUTPUT
All the leap years between 1900 t0 2002 are
1904 is a Leap year
1908 is a Leap year
1912 is a Leap year
1916 is a Leap year
1920 is a Leap year
1924 is a Leap year
1928 is a Leap year
1932 is a Leap year
1936 is a Leap year
1940 is a Leap year
1944 is a Leap year
1948 is a Leap year
1952 is a Leap year
1956 is a Leap year
1960 is a Leap year
1964 is a Leap year
1968 is a Leap year
1972 is a Leap year
1976 is a Leap year
1980 is a Leap year
1984 is a Leap year
1988 is a Leap year
1992 is a Leap year
1996 is a Leap year
2000 is a Leap year
[Link] a c++ program to add 10 consecutive numbers starting from 1 by
using while loop.
#include<iostream>
using namespace std;
int main()
int a=1,sum=0;
while(a<=10)
cout<<"\t"<<a;
sum=sum+a;
a++;
cout<<"\n sum of the numbers="<<sum;
return 0;
OUTPUT
1 2 3 4 5 6 7 8 9 10 sum
of the numbers=55
[Link] a c++ program to calculate the sum of individual digits of an
enterd number.
#include<iostream>
using namespace std;
int main()
{
int sum=0,num,t;
cout<<"\nEnter a number ";
cin>>num;
t=num;
while(t!=0)
{
sum=sum+t%10;
t=t/10;
}
cout<<"\n Sum of the indivisual digits of the number "<<num<<" is "<<sum;
return 0;
}
OUTPUT
Enter a number 953
Sum of the indivisual digits of the number 953 is 17
[Link] a c++ program to check whether the entered number is palindrom
or not.
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"\nEnter a number ";
cin>>num;
int a=num,b=0;
while(a!=0)
{
b=b*10+a%10;
a=a/10;
}
if(num==b)
cout<<"\nThe given number "<<num<<" is palindrom";
else
cout<<"\nThe given number "<<num<<" is not palindrom";
return 0;
}
OUTPUT
Enter a number 12321
The given number 12321 is palindrom
[Link] a c++ program to display the data by using class.
#include <iostream> using
namespace std
class item
{
private: // It's good pracƟce
to make member variables
private
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void)
{
cout << "NUMBER: " <<
number << "\n";
cout << "COST: " << cost <<
"\n";
}
};
void item::getdata(int a,
float b)
{
number = a;
cost = b;
}
int main()
{
item x;
cout << "\nObject x \n"; //
Corrected quotes and syntax
[Link](100, 299.95);
[Link]();
item y;
cout << "\nObject y \n"; //
Corrected quotes and syntax
[Link](200, 175.50);
[Link]();
return 0;
}
OUTPUT
Object x
NUMBER: 100
COST: 299.95
Object y
NUMBER: 200
COST: 175.50
[Link] a c++ program to find 1+2+3+...+n.
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
sum+=i;
i++;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 10
Sum of the serie = 55
[Link] a c++ program to find 1+1/2+1/3+1/4+...+1/n.
#include<iostream>
using namespace std;
int main()
{
float i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
sum=sum+1/i;
i++;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 3
Sum of the serie = 1.83333
[Link] a c++ program to find factorial of a given number.
#include<iostream>
using namespace std;
int main()
{
float i=1,fact=1,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
fact*=i;
i++;
}
cout<<"Factorial of the number "<<n<<" is = "<<fact;
return 0;
}
OUTPUT
Enter a number n= 5
Factorial of the number 5 is = 120
[Link] a c++ program to find 1+1/3+1/5+...+1/n
include<iostream>
using namespace std;
int main()
{
float i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
sum=sum+1/i;
i+=2;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 5
Sum of the serie = 1.53333
[Link] a c++ program to find 1+3+5+...+n.
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
sum+=i;
i+=2;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 5
Sum of the serie = 9
[Link] a c++ program to find 1*3*5*...*n.
#include<iostream>
using namespace std;
int main()
{
float i=1,prod=1,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
prod*=i;
i+=2;
}
cout<<"Prod of the serie = "<<prod;
return 0;
}
OUTPUT
Enter a number n= 5
Prod of the serie = 15
[Link] a c++ program to find 1+1/4+1/7+...+1/n.
#include<iostream>
using namespace std;
int main()
{
float i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
sum=sum+1/i;
i+=3;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 7
Sum of the serie = 1.39286
[Link] a c++ program to find 1-2+3-4+...+n.
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0,n;
cout<<"Enter a number n= ";
cin>>n;
while(i<=n)
{
if(i%2==0)
sum-=i;
else
sum+=i;
i++;
}
cout<<"Sum of the serie = "<<sum;
return 0;
}
OUTPUT
Enter a number n= 5
Sum of the serie = 3