Programs On C++
Programs On C++
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float a,b,c,s,area;
cin>>a;
cin>>b;
cin>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"\narea="<<area;
getch();
}
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
getch();
}
conditional
operator
{
clrscr();
int n;
cout<<"\nenter age";
cin>>n;
(n>=18)?cout<<"\neligible
vote":cout<<"\nnot eligible to vote";
getch();
}
if it of student A
to
if is of student B
r=((a/2)%==0)?(a*a):(a*a*a);
cout<<"\nresult is"<<r;
getch();
}
If number is even
If number is odd
clrscr();
float n,r,out;
cout<<"\nenter radius of the circle";
cin>>n;
cout<<"\nenter 1 for area and 2 for perimeter";
cin>>r;
out=(r==1)?(3.14*n*n):(2*3.14*n);
cout<<"\nyour output is"<<out;
getch();
}
If user enter 1
If user enter 2
{
clrscr();
int n;
cout<<"\nenter age";
cin>>n;
(n>=18)?cout<<"\neligible to vote":cout<<"\nnot eligible to
vote";
getch();
}
if age is less than 18
if no is odd
structure
else
cout<<"Enter a number between 1-7";
getch ();
}
if(m==6)
cout<<"JUNE=30";
if(m==7)
cout<<"JULY=31";
if(m==8)
cout<<"AUGUST=31";
if(m==9)
cout<<"SEPTEMBER=30";
if(m==10)
cout<<"OCTOBER=31";
if(m==11)
cout<<"NOVEMBER=30";
if(m==12)
cout<<"DECEMBER=31";
getch();
}
clrscr();
cout<<"\nenter first number";
cin>>a;
cout<<"\nenter second number";
cin>>b;
cout<<"\nenter the operator";
cin>>ch;
if (ch=='+')
cout<<a+b;
else if(ch=='-')
cout<<a-b;
else if(ch=='*')
cout<<a*b;
else if(ch=='/')
cout<<a/b;
else if
(ch=='%')
cout<<a%b;
getch();
}
cin>>A;
if((A=='a')||(A=='e')||(A=='i')||(A=='o')||(A=='u'))
cout<<"vowel";
else
cout<<"consonant";
getch();
}
int main()
{
clrscr();
int val;
int Note500=0;
int Note200=0;
int Note100=0;
int Note50=0;
int Note20=0;
int Note10=0;
int Note5=0;
int Note2=0;
int Note1=0;
cin>> val;
while(val!=0)
{
if(val>=500)
{
Note500++;
val=val-500;
}
else
if(val>=200)
{
Note200++;
val=val-200;
}
else if( val>=100)
{
Note100++;
val=val-100;
}
else if(val>=50)
{
Note50++;
val=val-50;
}
else if(val>=20)
{
Note20++;
val=val-20;
}
else if(val>=10)
{
Note10++;
val=val-10;
}
else if(val>=5)
{
Note5++;
val=val-5;
}
else if(val>=2)
{
Note2++;
val=val-2;
}
else if(val>=1)
{
Note1++;
val=val-1;
}
cout<<"\nNote500"<<note500<<"\nNote200"<<note200<<"\nNote100"<<
note100<<"\nNote50"<<note50<<"\nNote20"<<note20<<"\nNote10"<<<
note10<"\nNote5"<<<note5<"\nNote2"<<"\\nNote1";
getch();
return 0;
{
clrscr();
int i,sum;
for(i=0;i<=100;i=i+2)
{sum=sum+i;
}
cout<<sum;
getch();
}
int b;
cout<<"Enter the number";
cin>>a;
b=a;
ans=0;
while(a!=0)
{ rem=a%10;
ans=ans+(rem*rem*rem);
a=a/10;
}
if(ans==b)
cout<<"\nAmstrong number";
else
cout<<"Not a Armstrong number";
getch();
}