Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

PRACTICAL FILE

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 

2 WAP Swap Two Numbers 

3 WAP Find Factorial of Number 


4 WAP Calculate Area and
Circumference of Circle

5 WAP Check Palindrome or Not 

6 WAP Find Largest of Three


Numbers 
7 WAP to Draw pattern 

8 WAP to Draw pattern 

9 WAP One Dimensional Array


Program
10 WAP to Find Largest Element in
Array  

11 WAP to Add Two Matrices  


12 WAP Concatenate String  

13 WAP to Reverse String 

14 WAP to convert Lowercase to


Uppercase  

15 WAP to check leap year


1).WAP ask to the user to enter the two numbers along with operator to
perform particular operation (addition, subtraction, multiplication and
division) according to the user. 

#include<iostream.h> 

#include<conio.h> 

void main() 

clrscr(); 

int a, b; 

char ch; 

cout<<"Enter first Number :"; 

cin>>a; 

cout<<"Enter second Number :"; 

cin>>b; 

cout<<"Enter operator (+, -, *, /) :"; 

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:-

2). WAP Swap Two Numbers 


 

#include<iostream.h> 

#include<conio.h> 

void main() 

clrscr(); 

int num1, num2, swap; 

cout<<"Enter two number : "; 

cout<<"\nFirst Number : "; 

cin>>num1; 
cout<<"Second Number : "; 

cin>>num2; 

swap=num1; 

num1=num2; 

num2=swap; 

cout<<"The value of first and second number after swapping was \n"; 

cout<<"First Number = "<<num1<<"\n"<<"Second Number = "<<num2; 

getch(); 

When the above C++ program was compiled and executed, it will produce the
following result: 

3). WAP Find Factorial of Number 


 #include<iostream.h> 

#include<conio.h> 

void main() 

clrscr(); 

int num, i, fact=1; 

cout<<"Enter a number : "; 

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(); 

float r, area, circum; 

cout<<"Enter the radius of the circle :"; 

cin>>r; 

area=3.14*r*r; 

circum=2*3.14*r; 

cout<<"Area of the circle = "<<area<<"\nCircumference of the circle = "<<circum<<"\n"; 

getch(); 

When the above C++ program was compiled and executed, it will produce the
following result: 

5).WAP Check Palindrome or Not  


#include<iostream.h> 

#include<conio.h> 

void main()      

clrscr(); 

int num, rem, orig, rev=0; 

cout<<"Enter a number : "; 

cin>>num; 

orig=num; 

while(num!=0) 

rem=num%10; 

rev=rev*10 + rem; 

num=num/10; 

if(rev==orig)  // check if original number was equal to its reverse 

cout<<"Palindrome"; 

else 

cout<<"Not Palindrome"; 

getch(); 

 
When the above C++ program was compiled and executed, it will produce the
following result: 

6). WAP Find Largest of Three Numbers 


#include<iostream.h> 

#include<conio.h> 

void main() 

clrscr(); 

int a, b, c, big; 

cout<<"Enter three numbers : "; 

cin>>a>>b>>c; 

//let a was the biggest 

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++) 

for(j=0; j<k; j++) 

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; 

for(j=0; j<=i; j++) 

cout<<num<<" "; 

num++; 

cout<<"\n"; 

getch(); 

}  When the above C++ program was compiled and executed, it will produce


the following result: 

9).WAP One Dimensional Array Program


#include<stdio.h> 
#include<conio.h> 

void main() 

clrscr(); 

int arr[50], n; 

cout<<"How many element you want to store in the array ? "; 

cin>>n; 

cout<<"Enter "<<n<<" element to store in the array : "; 

for(int i=0; i<n; i++) 

cin>>arr[i]; 

cout<<"The Elements in the Array was : \n"; 

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: 

10).WAP to Find Largest Element in Array 


#include<iostream.h> 
#include<conio.h> 

void main() 

clrscr(); 

int large, arr[50], size, i; 

cout<<"Enter Array Size (max 50) : "; 

cin>>size; 

cout<<"Enter array elements : "; 

for(i=0; i<size; i++) 

cin>>arr[i]; 

cout<<"Searching for largest number ...\n\n"; 

large=arr[0]; 

for(i=0; i<size; i++) 

if(large<arr[i]) 

large=arr[i]; 

cout<<"Largest Number = "<<large; 

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(); 

int mat1[3][3], mat2[3][3], i, j, mat3[3][3]; 

cout<<"Enter matrix 1 elements :"; 

for(i=0; i<3; i++) 

for(j=0; j<3; j++) 

cin>>mat1[i][j]; 

cout<<"Enter matrix 2 elements :"; 

for(i=0; i<3; i++) 

for(j=0; j<3; j++) 

cin>>mat2[i][j]; 

cout<<"Adding the two matrix to form the third matrix .....\n"; 

for(i=0; i<3; i++) 

for(j=0; j<3; j++) 

mat3[i][j]=mat1[i][j]+mat2[i][j]; 

cout<<"The two matrix added successfully...!!"; 

cout<<"The new matrix will be :\n"; 

for(i=0; i<3; i++) 

for(j=0; j<3; j++) 

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]; 

cout<<"Enter first string : "; 

gets(str1); 

cout<<"Enter second string : "; 

gets(str2); 

strcat(str1, str2); 

cout<<"String after concatenation was "<<str1; 

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; 

cout<<"Enter the String : "; 

gets(str); 

i=0; 

j=strlen(str)-1; 

while(i<j) 

temp=str[i]; 

str[i]=str[j]; 

str[j]=temp; 

i++; 
j--; 

cout<<"Reverse of the String = "<<str; 

getch(); 

When the above C++ program was compiled and executed, it will produce the
following result: 

14).WAP to convert Lowercase to Uppercase  

#include<iostream.h> 

#include<conio.h> 

#include<string.h> 

void main() 

  clrscr(); 

  char str[20]; 

  int i; 

  cout<<"Enter the String (Enter First Name) : "; 

  cin>>str; 

  for(i=0;i<=strlen(str);i++) 

  { 

    if(str[i]>=97 && str[i]<=122) 
    { 

str[i]=str[i]-32; 

    } 

  } 

  cout<<"\nThe String in Uppercase = "<<str; 

  getch(); 

When the above C++ program was compiled and executed, it will produce the
following result: 

15). WAP to check leap year


#include<iostream.h>

#include<conio.h>

void main ()  

clrscr();

int year;

cout << "Enter a year you want to check: ";

cin >> year;

if (year % 4 == 0)

{
if (year % 100 == 0)

if(year % 400 == 0)

cout << year << " is a leap year." << endl;

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: 

You might also like