XI Programs
XI Programs
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\n Welcome to C++";
getch();
}
Output:
Program to calculate addition of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,add;
clrscr();
cout<<"\n Enter Two Numbers";
cin>>num1>>num2;
add=num1+num2;
cout<<"\n Addition is="<<add;
getch();
}
Output:
Program to calculate subtraction of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,sub;
clrscr();
cout<<"\n Enter Two Numbers";
cin>>num1>>num2;
sub=num1-num2;
cout<<"\n Subtraction is="<<sub;
getch();
}
Output:
Program to calculate division of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,div;
clrscr();
cout<<"\n Enter Two Numbers";
cin>>num1>>num2;
div=num1/num2;
cout<<"\n Division is="<<div;
getch();
}
Output:
Program to calculate Area of Circle
#include<iostream.h>
#include<conio.h>
void main()
{
float r,area;
clrscr();
cout<<"\n Enter Radius";
cin>>r;
area=3.14*r*r;
cout<<"\n Area of Circle="<<area;
getch();
}
Output:
Program to calculate Area of Rectangle
#include<iostream.h>
#include<conio.h>
void main()
{
int length,breadth,area;
clrscr();
cout<<"\n Enter Length and Breadth";
cin>>length>>breadth;
area=length*breadth;
cout<<"\n Area of Rectangle="<<area;
getch();
}
Output:
Program to calculate average of three numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,num3,avg;
clrscr();
cout<<"\n Enter Three Numbers";
cin>>num1>>num2>>num3;
avg=(num1+num2+num3)/3;
cout<<"\n Average is="<<avg;
getch();
}
Output:
Program to perform addition subtraction multiplication division within
a same program
#include<iostream.h>
#include<conio.h>
void main()
{
int num1,num2,add,sub,mul,div;
clrscr();
cout<<"\n Enter Two Numbers";
cin>>num1>>num2;
cout<<"\n ****Addition****";
add=num1+num2;
cout<<"\n Addition is="<<add;
cout<<"\n ****Subtraction****";
sub=num1-num2;
cout<<"\n Subtraction is="<<sub;
cout<<"\n ****Multiplication****";
mul=num1*num2;
cout<<"\n Multiplication is="<<mul;
cout<<"\n ****Division****";
div=num1/num2;
cout<<"\n Division is="<<div;
getch();
}
Output:
Program to Check given number is odd or even
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
clrscr();
cout<<"\n Enter Number to check it it even or odd";
cin>>num;
if(num%2==0)
{
cout<<"\n Number is Even";
}
else
{
cout<<"\n Number is Odd";
}
getch();
}
Output:
Program to Check given year is leap or not
#include<iostream.h>
#include<conio.h>
void main()
{
int year;
clrscr();
cout<<"\n Enter Year to check whether it it Leap or not";
cin>>year;
if(year%4==0)
{
cout<<"\n Year is Leap";
}
else
{
cout<<"\n Year is not Leap";
}
getch();
}
Output:
Program to calculate percentage and grade of student
#include<iostream.h>
#include<conio.h>
void main()
{
int phy_marks,chem_marks,maths_marks,total;
float percentage;
clrscr();
cout<<"\n Enter Physics Marks, Chemistry Marks and Maths Marks";
cin>>phy_marks>>chem_marks>>maths_marks;
total=phy_marks+chem_marks+maths_marks;
percentage=total/3.0;
cout<<"\n Percentage is="<<percentage<<"%";
if(percentage>=90)
{
cout<<"\n Grade A";
}
else if(percentage>=80 && percentage<90)
{
cout<<"\n Grade B";
}
else if(percentage>=60 && percentage<80)
{
cout<<"\n Grade C";
}
else if(percentage>=40 && percentage<60)
{
cout<<"\n Grade D";
}
else
{
cout<<"\n Fail";
}
getch();
}
Output:
Program to display First 10 natural numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
cout<<"\n Natural Numbers";
while(i<=10)
{
cout<<i<<"\n";
i++;
}
getch();
}
Output:
Program to display n even numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int i=1,n;
clrscr();
cout<<"\n Enter Limit value to print Even numbers";
cin>>n;
cout<<"\n Even Numbers\n";
while(i<=n)
{
if(i%2==0)
{
cout<<i<<"\n";
}
i++;
}
getch();
}
Output:
Program to calculate sum of first n natural numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int sum=0,n;
clrscr();
cout<<"\n Enter Number";
cin>>n;
while(n>0)
{
sum=sum+n;
n--;
}
cout<<"\n Sum is="<<sum;
getch();
}
Output:
Program to display following pattern
*****
*****
*****
*****
*****
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
cout<<"\n Star Pattern\n";
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
cout<<”*”;
}
cout<<"\n";
}
getch();
}
Output:
Program to display following pattern
12345
12345
12345
12345
12345
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
cout<<"\n Star Pattern\n";
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
cout<<j;
}
cout<<"\n";
}
getch();
}
Output:
Program to create user defined function
void cricket();
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cricket();
cout<<"\n I am in Main Function";
getch();
}
void cricket()
{
cout<<"\n I like to play cricket";
}
Output: