Practical File OF Computer Science (On C++ Programing)
Practical File OF Computer Science (On C++ Programing)
Practical File OF Computer Science (On C++ Programing)
OF
COMPUTER SCIENCE
(on C++ Programing)
INDEX
SERIAL PROGRAM NAME PAGE SIGNATURE
NO. NUMBER
1 WAP ask to the user to enter the
two numbers along with operator
to perform particular operation
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
char ch;
cin>>a;
cin>>b;
cin>>c);
if(ch=='+')
cout<<"Result = "<<a+b;
else if(ch=='-')
cout<<"Result = "<<a-b;
else if(ch=='*')
cout<<"Result = "<<a*b;
else if(ch=='/')
cout<<"Result = "<<a/b;
else
cout<<"Wrong Operator!!!";
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\nFirst Number : ";
cin>>num1;
cout<<"Second Number : ";
cin>>num2;
swap=num1;
num1=num2;
num2=swap;
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
#include<conio.h>
void main()
{
clrscr();
int num, i, fact=1;
cin>>num;
for(i=num; i>0; i--)
{
fact=fact*i;
}
cout<<"Factorial of "<<num<<" was "<<fact;
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
4). WAP Calculate Area and Circumference of Circle
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cin>>r;
area=3.14*r*r;
circum=2*3.14*r;
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
#include<conio.h>
void main()
{
clrscr();
int num, rem, orig, rev=0;
cin>>num;
orig=num;
while(num!=0)
{
rem=num%10;
rev=rev*10 + rem;
num=num/10;
}
{
cout<<"Palindrome";
}
else
{
cout<<"Not Palindrome";
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
#include<conio.h>
void main()
{
clrscr();
int a, b, c, big;
cin>>a>>b>>c;
big=a;
if(big<b)
{
if(b>c)
{
big=b;
}
else
{
big=c;
}
}
else if(big<c)
{
if(c>b)
{
big=c;
}
else
{
big=b;
}
}
else
{
big=a;
}
cout<<"Biggest number was "<<big;
getch();
When the above C++ program was compiled and executed, it will produce the
following result:
7). WAP to Draw pattern
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, k=1;
for(i=0; i<5; i++)
{
{
cout<<"* ";
}
k=k+2;
cout<<"\n";
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
8).WAP to Draw pattern
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, j, num=1;
for(i=0; i<5; i++)
{
num=1;
{
cout<<num<<" ";
num++;
}
cout<<"\n";
}
getch();
void main()
{
clrscr();
int arr[50], n;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>arr[i];
}
for(i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
void main()
{
clrscr();
int large, arr[50], size, i;
cin>>size;
for(i=0; i<size; i++)
{
cin>>arr[i];
}
large=arr[0];
for(i=0; i<size; i++)
{
if(large<arr[i])
{
large=arr[i];
}
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
11). WAP to Add Two Matrices
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(i=0; i<3; i++)
{
{
cin>>mat1[i][j];
}
}
for(i=0; i<3; i++)
{
{
cin>>mat2[i][j];
}
}
for(i=0; i<3; i++)
{
{
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
}
for(i=0; i<3; i++)
{
{
cout<<mat3[i][j]<<" ";
}
cout<<"\n";
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
12). WAP Concatenate String
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char str1[50], str2[50];
gets(str1);
gets(str2);
strcat(str1, str2);
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
13).WAP to Reverse String
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100], temp;
int i=0, j;
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[20];
int i;
cin>>str;
for(i=0;i<=strlen(str);i++)
{
if(str[i]>=97 && str[i]<=122)
{
str[i]=str[i]-32;
}
}
getch();
}
When the above C++ program was compiled and executed, it will produce the
following result:
#include<conio.h>
void main ()
clrscr();
int year;
if (year % 4 == 0)
{
if (year % 100 == 0)
if(year % 400 == 0)
else cout << year << " is not a leap year." << endl;
else cout << year << " is a leap year." << endl;
else cout << year << " is not a leap year." << endl;
getch();
When the above C++ program was compiled and executed, it will produce the
following result: