You are on page 1of 10

LABMNU

List of Practicals:
1 | Page

1. Write a program in C++ that reads a character from keyboard and


displays its corresponding ASCII value on the screen.
2. Write a program in C++ which will ask for a temperature in Fahrenheit
and display it in Celsius and vice versa.
3. Write a program in C++ to compute the factorial of a given number.
4. Write a program in C++ to display the Fibonacci series upto n numbers.
5. Write a program in C++ that finds the GCD of two numbers using
recursion.
6. Write a program in C++ to display the reverse of the given number using
recursion.
7. Write a program in C++ to find the smallest number among the set
numbers using recursion.
8. Write a program in C++ to compute the number m to a power n by
declaring a function power().
9. Write a program in C++ to compute the area of a triangle and a circle by
overloading the area() function.
10.Write a program in C++ to read a matrix of size m x n from the keyboard
and display the same on the screen using functions.
11.Write a program in C++ using function that receives the two matrix
objects as arguments and return a new matrix object containing their
multiplication result.
12.Create a class FLOAT that contains one float data member. Overload all
the four arithmetic operators so that they operate on the objects of
FLOAT.
13.Using the concept of pointers wrote a program that swaps the private data
values of two data objects of the same class type.
14.Write a program in C++ which reads a text from the keyboard and
displays the numbers of lines, words and characters with left justified
strings and right justified numbers.
15.Write a program in C++ that reads a text file and creates another file that
is identical except that every sequence of consecutive blank spaces is
replaced by a single space.

2 | Page

//Write a program in C++ that reads a character from keyboard


and displays its corresponding ASCII value on the screen.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
char alpha;
cout<<"Enter character: ";
cin>>alpha;
int x=toascii(alpha);
cout<<"ASCII value of character is: "<<x;

getch();
}

OUTPUT:

3 | Page

//Write a program in C++ which will ask for a temperature in


Fahrenheit and display it in Celsius and vice versa.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x;
for(int r=1;r<3;r++)
{
cout<<"\nEnter choice:\n1. Celsius ---> Fahrenheit\n2. Fahrenheit --->
Celsius\n ";
cin>>x;
switch(x)
{
case 1:
{
float C,F=1;
cout<<"\nEnter Temperature (in Celsius): ";
cin>>C;
F=(C*1.8)+32;
cout<<"\nThe Temperature (in Fahrenheit)= "<<F;
break;
}
case 2:
{
float C=1,F;
cout<<"\nEnter Temperature (in Fahrenheit): ";
cin>>F;
C=(F-32)*5/9;
cout<<"\nThe Temperature (in Celsius): "<<C;
break;
}
default:
{
cout<<"\n\nINVALID ENTRY!!!";
break;
}
}
}

4 | Page

getch();

OUTPUT:

5 | Page

//Write a program in C++ to compute the factorial of a given


number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double n,factorial;
cout<<"Enter a number ";
cin>>n;
factorial=1;
for(int i=n;i>=1;i--)
factorial=factorial*i;
cout<<"The Factorial of "<<n<<" is: "<<factorial;
getch();
}

OUTPUT:

6 | Page

//Write a program in C++ to display the Fibonacci series upto n


numbers.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double n,a1,a2,next;
a1=1;
a2=1;
cout<<"\nEnter the number of terms of Fibonacci series to be displayed ";
cin>>n;
cout<<"\n\nFirst "<<n<<" terms of Fibonacci series are:\n"<<a1<<""<<a2<<"
";
for(int c=0;c<n;c++)
{
next=a1+a2;
a1=a2;
a2=next;
cout<<next<<" ";
}
getch();

OUTPUT:

7 | Page

//Write a program in C++ that finds the GCD of two numbers


using recursion.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,gcd=1;
cout<<"Enter the two numbers:\n";
cin>>x>>y;
if(x<y)
{
for(int i=1;i<=x;++i)
{
if((x%i==0)&&(y%i==0))
gcd=i;
}
}
else
{
for(int i=1;i<=y;++i)
{
if((x%i==0)&&(y%i==0))
gcd=i;
}
}
cout<<"\n\nGCD: "<<gcd;
getch();
}

8 | Page

OUTPUT:

//Write a program in C++ to display the reverse of the given


number using recursion.
#include<iostream.h>
#include<conio.h>
void main()
{
long num,n,rem=0,rev=0;
clrscr();

cout<<"Enter the Number: ";


cin>>num;

while(num!=0)
{
rem=num%10;
num=num/10;
rev=rev*10+rem;

9 | Page

}
cout<<"\nReverse: "<<rev;
getch();
}

OUTPUT:

10 | P a g e

You might also like