#include
#include
void main()
{
int bin[20]={0},n,i=0,ch=0;
printf("\n enter the no.");
scanf("%d",&n);
while(n!=0)
{
bin[i]=n%2;
i++;
n=n/2;
}
printf("\n number is=");
for(;i>=0;i--)
{
printf("%d",bin[i]);
}
getch();
}
=======================================================================
This is a program in which a circle is printed madly. :lol: :lol:
#include
#include
#include
#include
#include
void main()
{
int x,y,i,a=DETECT,b=0;
initgraph(&a,&b,"c:\\tc\\bgi");
randomize();
for(i=0;i<=50;i++)
{
clrscr();
x=random(250);
y=random(250);
circle(x+100,y+100,10);
delay(100);
}
getch();
============================================================
// program to convert decimal numbers to binary.
#include
#include
void main()
{
int bin[20]={0},n,i=0,ch=0;
printf("\n enter the no.");
scanf("%d",&n);
while(n!=0)
{
bin[i]=n%2;
i++;
n=n/2;
}
printf("\n number is=");
for(;i>=0;i--)
{
printf("%d",bin[i]);
}
getch();
}
===================================================
//program to convert binary to octal
#include
#include
int pow(int arg)
{
int temp=1,i;
for(i=1;i<=arg;i++)
{
temp=2*temp;
}
return temp;
}
void main()
{
int bin[15]={0},oct[15]={0},i=0,j,n,x=0,k;
printf("\n enter the total no. of digits");
scanf("%d",&n);
for(i=14-n+1;i<=14;i++)
{
printf("\n enter the digit");
scanf("%d",&bin[i]);
}
k=14;
for(i=14;i>=14-n+1;)
{
x=0;
for(j=0;j<=2;j++)
{
x=x+bin[i-j]*pow(j);
}
oct[k]=x;
i=i-3;
k--;
}
printf("\n number is=");
for(i=0;i<=14;i++)
{
printf("%d",oct[i]);
}
getch();
}
======================================================================
this program prints askii values.
#include
#include
void main()
{
char c;
int i;
clrscr();
printf("press esc if you want to exit:\n");
while(1)
{
fflush(stdin);
c=getch();
clrscr();
if(c==27)
{
break;
}
printf("%d",c);
}
}
=======================================================================
A program to findcalc area, surface area, volume, total surface area etc. of numerous 2D and 3D figures using functions:-
#include
#include
using namespace std;
void line(void);
void cuboid(void);
void cube(void);
void cylinder(void);
void cone(void);
void sphere(void);
void hemisphere(void);
void triangle(void);
void rectangle(void);
void square(void);
void circle(void);
void parallelogram(void);
int main()
{
int o1,o2;
do{
cout<<"\n\n1. 3-D Figures"
<<"\n\n2. Plane Figures"
<<"\n\n3. Exit"
<<"\n\nEnter your choice -->\t";
cin>>o1;
switch(o1)
{
case 1: cout<<"\n\n";
line();
cout<<"\n\t\t\t\t3-D Figures\n\n";
line();
cout<<"\n\n1. Cuboid"
<<"\n\n2. Cube"
<<"\n\n3. Cylinder"
<<"\n\n4. Cone"
<<"\n\n5. Sphere"
<<"\n\n6. Hemisphere"
<<"\n\n7. Main Menu"
<<"\n\nEnter your choice -->\t";
cin>>o2;
switch(o2)
{
case 1: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tCuboid\n\n";
line();
cuboid();
break;
case 2: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tCube\n\n";
line();
cube();
break;
case 3: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tCylinder\n\n";
line();
cylinder();
break;
case 4: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tCone\n\n";
line();
cone();
break;
case 5: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tSphere\n\n";
line();
sphere();
break;
case 6: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tHemisphere\n\n";
line();
hemisphere();
break;
case 7: break;
default: cout<<"\n\nInvalid Input\a\a\a";
}
break;
case 2:
cout<<"\n\n";
line();
cout<<"\n\t\t\t\tPlane Figures\n\n";
line();
cout<<"\n\n1. Traingle"
<<"\n\n2. Rectangle"
<<"\n\n3. Sqaure"
<<"\n\n4. Circle"
<<"\n\n5. Parallelogram"
<<"\n\n6. Main Menu"
<<"\n\nEnter your choice -->\t";
cin>>o2;
switch(o2)
{
case 1: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tTraingle\n\n";
line();
triangle();
break;
case 2: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tRectangle\n\n";
line();
rectangle();
break;
case 3: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tSquare\n\n";
line();
square();
break;
case 4: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tCircle\n\n";
line();
circle();
break;
case 5: cout<<"\n\n";
line();
cout<<"\n\t\t\t\tParallelogram\n\n";
line();
parallelogram();
break;
case 6: break;
default: cout<<"\n\nInvalid Input\a\a\a";
}
break;
case 3: cout<<"\n\nPress any key to exit.\a";
break;
default: cout<<"\n\nInvalid Input\a\a\a\a";
}
}while(o1!=3);
return 0;
}
void line()
{
int i;
for (i=0;i<80;i++)
cout<<"*";
}
void cuboid()
{
float l,b,h,a,v;
cout<<"\n\nEnter length of cuboid -->\t";
cin>>l;
cout<<"\n\nEnter breadth of cuboid -->\t";
cin>>b;
cout<<"\n\nEnter height of cuboid -->\t";
cin>>h;
v=l*b*h;
a=2*(l*b+b*h+l*h);
cout<<"\n\nVolume of cuboid is "<
void cube()
{
float l,a,v;
cout<<"\n\nEnter length of side of cube -->\t";
cin>>l;
v=l*l*l;
a=6*l*l;
cout<<"\n\nVolume of cube is "<
void cylinder()
{
float r,h,v,c,t;
cout<<"\n\nEnter radius of cylinder -->\t";
cin>>r;
cout<<"\n\nEnter height of cylinder -->\t";
cin>>h;
v=3.14*r*r*h;
c=2*3.14*r*h;
t=3.14*r*(2*h+r);
cout<<"\n\nVolume of cylinder is "<
void cone()
{
float r,h,l,v,c,t;
cout<<"\n\nEnter radius of cone -->\t";
cin>>r;
cout<<"\n\nEnter height of cone -->\t";
cin>>h;
l=sqrt(r*r+h*h);
v=(3.14*r*r*h)/3;
c=3.14*r*l;
t=3.14*r*(l+r);
cout<<"\n\nSlant height of cone is "<
void sphere()
{
float r,v,a;
cout<<"\n\nEnter radius of sphere -->\t";
cin>>r;
v=(4*3.14*r*r*r)/3;
a=4+3.14*r*r;
cout<<"\n\nVolume of sphere is "<
void hemisphere()
{
float r,v,c,t;
cout<<"\n\nEnter radius of hemisphere -->\t";
cin>>r;
v=(2*3.14*r*r*r)/3;
c=2*3.14*r*r;
t=3*3.14*r*r;
cout<<"\n\nVolume of hemisphere is "<
void triangle()
{
float b,h,a;
cout<<"\n\nEnter base of triangle -->\t";
cin>>b;
cout<<"\n\nEnter height of triangle -->\t";
cin>>h;
a=(b*h)/2;
cout<<"\n\nArea of the triangle is "<
}
void rectangle()
{
float l,b,a,p;
cout<<"\n\nEnter length of rectangle -->\t";
cin>>l;
cout<<"\n\nEnter breadth of rectangle -->\t";
cin>>b;
a=l*b;
p=2*(l+b);
cout<<"\n\nArea of rectangle is "< cout<<"\n\nPerimeter of rectangle is "<}
void square()
{
float s,a,p;
cout<<"\n\nEnter length of side of square -->\t";
cin>>s;
a=s*s;
p=4*s;
cout<<"\n\nArea of square is "< cout<<"\n\nPerimeter of square is "<}
void circle()
{
float r,a,c;
cout<<"\n\nEnter radius of circle -->\t";
cin>>r;
a=3.14*r*r;
c=2*3.14*r;
cout<<"\n\nArea of circle is "< cout<<"\n\nCircumference of circle is "<
void parallelogram()
{
float b,h,a,p;
cout<<"\n\nEnter base of parallelogram -->\t";
cin>>b;
cout<<"\n\nEnter height of parallelogram -->\t";
cin>>h;
a=b*h;
p=2*(b+h);
cout<<"\n\nArea of parallelogram is "< cout<<"\n\nPerimeter of parallelogram is "<}
==================================================================
simple cows and bull game made by me...hehe taken some help.
Postby Sagar Agarwal on Thu Feb 14, 2008 10:16 am
#include
#include
#include
#include
#include
#include
int fany;
char gsm[5];
char word_list[84][5]={
"play","bark","take","make","bake","lake","fete","stay","fate",
"your","mine","fine","wine","pine","line","dine","time","seam",
"seem","deen","done","fume","home","corn","born","bite","poet",
"poem","loan","grin","turn","burn","meat","meet","goat","just",
"bike","city","pity","tiny","rest","test","fest","lest","soup","seal",
"lice","love","name","fame","lame","tame","bane","boon","pool",
"loop","away","yolk","folk","fist","jist","mist","list","game","slit",
"auto","hoot","boot","coup","late","rate","hate","mate","date",
"peel","feel","leaf","lite","kite","note","boat","four","nine","five"
};
void find()
{
randomize();
fany=random(84);
strcpy(gsm,word_list[fany]);
}
void main()
{
int i,j,tri=1,cow,bull;
char guess[5],nam1[15],ch;
char scr1[]={'W','E','L','C','O','M','E',' ','T','O',' ','.','.','.','\0'};
char scr2[]={'C','O','W','S',' ',' ','n',' ',' ','B','U','L','L','S','\0'};
do
{
clrscr();
cout<<"\n\n\n\n\t\t\t";
cout<
cout<
<<"\t 2. Play\n\n"
<<"\t 3. Exit\n\n\n\t\t";
cout<<"Enter Your Choice(1-3). : ";
cin>>j;
switch(j)
{
case 1:
clrscr();
cout<<"\n\n\nIn Cows-n-Bulls game,the Computer Will Think Of A 4-lettered Word."
<<"\nYou Have To Guess This Four Lettered Word By Typing Your Word."
<<"\n\nIf Your Word Has A Letter Which Is Correct And Is At Right Position, It Is BULL"
<<"\nIf Your Word Has A Letter Which Is NOT Correct Or Not At Right Position, It Is COW"
<<"\n\nThe Computer Will Tell You How Many Bulls And How Many Cows You Entered."
<<"\nOnce You Guess The Right Word The Game Ends. Or If You Decide To Quit,"
<<" The Computer Will Tell The Word It Thought Of And Then The Game Ends!"
<<"\n\n\n\t! H@PpY G@MiNg !\n";
cout<<"Press A Key . ";
getch();
break;
case 2:
clrscr();
cout<<"\nEnter Your Name : ";
gets(nam1);
tri=1;
find();
do
{
cout<<"\n\n\t"<
cow=bull=0;
for(i=0;i<4;i++)
{
if(gsm[i]!=guess[i])
cow++;
}
bull=(4-cow);
cout<<"\n\tYou Have "<
{
tri++;
cout<<"\n\tWant To QUIT ?";
cin>>ch;
if(ch=='y'||ch=='Y')
{
cout<<"\n\n\t\t The Word Was "<
break;
}
}
else
{
cout<<"\n\n\t\tCongrats! "<
getch();
break;
}
}while(1);
break;
case 3:
break;
default :
cout<<"\t\nWrong Choice Entered ! Correct Choice Range is 1.3";
break; }
}while(j>=1&&j<=2);
cout<<"\n\n\tPress A Key . ";
getch();
}
==================================================================
reverse case of character in the string entered by user
Postby Sagar Agarwal on Thu Feb 14, 2008 10:18 am
#include
#include
#include
void main()
{
clrscr();
char str[50]; char ch; int flag=0;
cout<<"Enter The String : ";
cin.getline(str,50);
cout<<"Enter The Character : ";
cin>>ch;
for(int i=0;i<50;i++)
{
if(str[i]==ch||str[i]==ch+32||str[i]==ch-32)
{
flag=1;
if(islower(str[i]))
{
str[i]=toupper(str[i]);
}
else if(isupper(str[i]))
{
str[i]=tolower(str[i]);
}
}
}
if(flag==0)
{
cout<<"Character Not Present In The String";
}
else
{
cout<<"String After Changing The Case Is :"<
getch();
}
===========================================================================
No comments:
Post a Comment