Write a program to display the sum of even number..
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,s=0;
for(i=2;i<=100;i=i+2)
{
s=s+i;
cout<<"+"<<i;
}
cout<<"="<<s;
getch();
}
#include<conio.h>
void main()
{
clrscr();
int i,s=0;
for(i=2;i<=100;i=i+2)
{
s=s+i;
cout<<"+"<<i;
}
cout<<"="<<s;
getch();
}
Here is the output :->
Simple program of cube and square
#include<iostream.h>
#include<conio.h>
class cool
{
private:
int n,s;
public:
void add()
{
cout<<"\n Enter the Number: ";
cin>>n;
}
void iff()
{
if((n%2)==0)
{
s=n*n;
cout<<s;
}
else
{
s=n*n*n;
cout<<s;
}
}
};
void main()
{
clrscr();
cool c;
c.add();
c.iff();
getch();
}
#include<conio.h>
class cool
{
private:
int n,s;
public:
void add()
{
cout<<"\n Enter the Number: ";
cin>>n;
}
void iff()
{
if((n%2)==0)
{
s=n*n;
cout<<s;
}
else
{
s=n*n*n;
cout<<s;
}
}
};
void main()
{
clrscr();
cool c;
c.add();
c.iff();
getch();
}
Here is the output:
Create a program of Math table......
#include<iostream.h>
#include<conio.h>
class table
{
private:
int i,a;
public:
void put()
{
cout<<"\n Enter The Number Upto Which U Want Table: ";
cin>>a;
}
void f()
{
for(i=1;i<=10;i++)
{
cout<<a<<"\t"<<"X"<<"\t"<<i<<"\t"<<"="<<"\t"<<a*i<<endl;
}
}
};
void main()
{
clrscr();
table t;
t.put();
t.f();
getch();
}
#include<conio.h>
class table
{
private:
int i,a;
public:
void put()
{
cout<<"\n Enter The Number Upto Which U Want Table: ";
cin>>a;
}
void f()
{
for(i=1;i<=10;i++)
{
cout<<a<<"\t"<<"X"<<"\t"<<i<<"\t"<<"="<<"\t"<<a*i<<endl;
}
}
};
void main()
{
clrscr();
table t;
t.put();
t.f();
getch();
}
Here is the output :)
Convert heights into feets and inch :-)
#include<iostream.h>
#include<conio.h>
void main()
{
float h,i,f;
clrscr();
cout<<"Enter Ur Height In Cms = "<<endl;
cin>>h;
f=h/30.48;
cout<<"Height in Feets = "<<f<<endl;
i=h/2.54;
cout<<"Height in Inch = "<<i<<endl;
getch();
}
#include<conio.h>
void main()
{
float h,i,f;
clrscr();
cout<<"Enter Ur Height In Cms = "<<endl;
cin>>h;
f=h/30.48;
cout<<"Height in Feets = "<<f<<endl;
i=h/2.54;
cout<<"Height in Inch = "<<i<<endl;
getch();
}
HERE IS THE OUTPUT :-)
PROGRAM TO VIEW ODD AND EVEN NUMBERS
#include<iostream.h>
#include<conio.h>
class cnd
{
private :
int n;
public :
void put()
{
cout<<"\n Enter The Number: ";
cin>>n;
}
void iff()
{
if(n==0)
{
cout<<"\n The number is zero";
}
else if((n%2)==0)
{
cout<<"\n The number is even";
}
else if((n%2)!=0)
{
cout<<"\n The number is odd";
}
}
};
void main()
{
clrscr();
cnd c;
c.put();
c.iff();
getch();
}
#include<conio.h>
class cnd
{
private :
int n;
public :
void put()
{
cout<<"\n Enter The Number: ";
cin>>n;
}
void iff()
{
if(n==0)
{
cout<<"\n The number is zero";
}
else if((n%2)==0)
{
cout<<"\n The number is even";
}
else if((n%2)!=0)
{
cout<<"\n The number is odd";
}
}
};
void main()
{
clrscr();
cnd c;
c.put();
c.iff();
getch();
}
HERE IS THE OUTPUT :)
WRITE A PROGRAM TO PRINT N PRIME NUMBERS
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n=0,i,l,j,k=2,a=0;
cout<<"Enter Limit"<<endl;
cin>>l;
while(n<l)
{
j=2;
a=0;
while(j<=k/2)
{
if(k%j==0)
a=a+1;
j++;
}
if(a==0)
{
cout<<"\t"<<k<<"\t";
}
else
l++;
n++;
k++;
}
getch();
}
#include<conio.h>
void main()
{
clrscr();
int n=0,i,l,j,k=2,a=0;
cout<<"Enter Limit"<<endl;
cin>>l;
while(n<l)
{
j=2;
a=0;
while(j<=k/2)
{
if(k%j==0)
a=a+1;
j++;
}
if(a==0)
{
cout<<"\t"<<k<<"\t";
}
else
l++;
n++;
k++;
}
getch();
}
HERE IS THE OUTPUT :)
Find out total and average
#include <iostream.h>
#include<conio.h>
float data[5];
float total;
float average;
void main ()
{
clrscr();
data[0] = 10.0;
data[1] = 20.0;
data[2] = 29.5;
data[3] = 40.5;
data[4] = 50.0;
total = data[0] + data[1] + data[2] + data[3] + data[4];
average = total / 5.0;
cout << "\n Total "<< total << " Average " << average << '\n';
getch();
}
float data[5];
float total;
float average;
void main ()
{
clrscr();
data[0] = 10.0;
data[1] = 20.0;
data[2] = 29.5;
data[3] = 40.5;
data[4] = 50.0;
total = data[0] + data[1] + data[2] + data[3] + data[4];
average = total / 5.0;
cout << "\n Total "<< total << " Average " << average << '\n';
getch();
}
No comments:
Post a Comment