0% found this document useful (0 votes)
14 views6 pages

x1cs1 Practicals

The document contains a series of C++ programming exercises that cover various fundamental concepts such as calculating averages, simple interest, area and perimeter of a rectangle, digit sum, temperature conversion, gross salary calculation, number swapping, and determining the largest number among three inputs. Each exercise includes a code snippet demonstrating the implementation of the respective concept. The document serves as a practical guide for beginners to learn basic programming skills in C++.

Uploaded by

varad04naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

x1cs1 Practicals

The document contains a series of C++ programming exercises that cover various fundamental concepts such as calculating averages, simple interest, area and perimeter of a rectangle, digit sum, temperature conversion, gross salary calculation, number swapping, and determining the largest number among three inputs. Each exercise includes a code snippet demonstrating the implementation of the respective concept. The document serves as a practical guide for beginners to learn basic programming skills in C++.

Uploaded by

varad04naik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

prac No 1: Average of three Numbers

#include <iostream>
#include<conio.h>
void main()
{
int a,b,c;
float avg;
cout<<”Enter 3 Numbers”;
cin>>a>>b>>c;
avg=(a+b+c)/3;
cout<<”\n Average=”<<avg;
getch();
}

prac NO 2:To calculate Simple Interest (SI=pnr/100)


#include <iostream>
#include<conio.h>
void main()
{
int p,n;
float r,si;
cout<<”\n Enter Principal Amount”;
cin>>p;
cout<<”\n Enter No of years”;
cin>>n;
cout<<”\n Enter Rate of Interest”;
cin>>r;
si=(p*n*r)/100;
cout<<”\n Simple Interest=”<<si;
getch();
}
Prac No 3: To Compute Area and Perimeter of Rectangle
#include <iostream>
#include<conio.h>
void main()
{
int l,b,p,a;
cout<<”\n Enter Length and Breadth”;
cin>>l>>b;
p=2*(l+b);
cout<<”\n Perimeter=”<<p;
a=l*b;
cout<<”\nArea=”<<a;
getch();
}

Prac No 4: To Find Sum of Individual digits:


#include<conio.h>
#include<iostream.h>
void main()
{
int d1,d2,d3,d4,d5,sum,number,n;
clrscr();
cin>>number;
cout<<"\n number"<<number;
n=number;
d1=n%10;
n=n/10;
d2=n%10;
n=n/10;
d3=n%10;
n=n/10;
d4=n%10;
n=n/10;
d5=n;
sum=d1+d2+d3+d4+d5;
cout<<"\n sum="<<sum;
getch();

}
prac No 5: To Convert a given Temperature in Celsius to Fahrenheit by using Formula
#include <iostream.h>
#include<conio.h>
void main() {
float fahren, celsius;
cout << "Enter the temperature in celsius\n";
cin >> celsius;
fahren =1.8 * celsius + 32;
cout << celsius <<"Centigrade is equal to " << fahren <<"Fahrenheit";
getch();
}
prac no 6:To calculate Gross Salary
#include<iostream.h>
#include<conio.h>
void main()
{
float basic,gross,da,hra;
cout<<"Enter Basic Salary of an employee:";
cin>>basic:
da=basic*0.4;
hra=basic*0.2;
gross=basic+hra+da;
cout<<"\n\t Basic Pay................"<<basic;
cout<<"\n\t Dearness Allowance......."<<da<<endl;
cout<<"\t House Rent Allowance......."<<hra<<endl;
cout<<"\t----------------"<<endl;
cout<<"\t Gross Salary.........."<<gross<<endl;
cout<<"\t----------------"<<endl;
getch();
}
Prac No 7: To Swap Two Numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int a = 2, b = 3;
cout << "Before swaping a = " <<a << " , b = " << b << endl;
int temp;
temp = a;
a = b;
b = temp;
cout << "After swaping a = " << a << " , b = " << b << endl;
getch();}
prac no 8
Program to check whether an integer is positive, negative or zero

#include <iostream>
#include<conio.h>
void main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
if (number > 0)
{
cout << "You entered a positive integer: " << number << endl;
}
else if (number < 0)
{
cout << "You entered a negative integer: " << number << endl;
}
else
{
cout << "You entered 0." << endl;
}
cout << "This line is always printed.";
getch();
}
prac no 9Write a C++ program to find largest among three numbers

#include<iostream.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
cout<<"enter 3 nos:";
cin>>a>>b>>c;
if(a>b&&a>c)
cout<<"max is :"<<a<<endl;
if (b>a&&b>c)
cout<<"max is:"<<b<<endl;
if(c>a&&c>b)
cout<<"max is :"<<c<<endl;
getch();
}
prac No:10 Calculate percentage and print result using Else---if Ladder

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int p,c,m,cs,rollno,total;
float per;
cout<<"\nEnter Roll No";
cin>>rollno;
cout<<"\n Enter Marks of 4 subjects";
cin>>p>>c>>m>>cs;
total=p+c+m+cs;
cout<<"\n Total="<<total;
per=total/4.0;
cout<<"\n Percentage="<<per;
if(per>=80&&per<100)
cout<<"\n Distinction";
else if(per>=60&&per<80)
cout<<"\n First class";
else if(per>=40&&per<60)
cout<<"\n Second class";
else if(per>=35&&per<40)
cout<<"\n Third class";
else
cout<<"\n Fail";
getch();
}
Prac No 11:Use of Scope Resolution Operator

#include<iostream.h>
#include <conio.h>
int m=10;
void main()
{
int m=20;
clrscr();
{
int k=m;
int m=30;
cout<<"we are in inner block\n";
cout<<"k="<<k<<"\n";
cout<<"local m="<< m<< "\n";
cout<<"global m="<<::m<<"\n";
getch();
}
}

You might also like