The Mind Reader:
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <time.h>
void fun(int x,int y,int n,int a)
{
textcolor(13);
gotoxy(x,y);
cprintf("%d->%c",n,a);
}
void box(int c,int r,int s,int y)
{
int i ;
textcolor(3);
gotoxy(s,y);
cprintf("%c",218);
for(i=s+1;i<c+1;i++)
{
gotoxy(i,y);
cprintf("%c",196);
}
for(i=s+1;i<c+1;i++)
{
gotoxy(i,r);
cprintf("%c",196);
}
gotoxy(c,y);
cprintf("%c",191);
for(i=y+1;i<r;i++)
{
gotoxy(s,i);
cprintf("%c",179);
}
for(i=y+1;i<r;i++)
{
gotoxy(c,i);
cprintf("%c",179);
}
gotoxy(s,i);
cprintf("%c",192);
gotoxy(c,i);
cprintf("%c",217);
}
void help()
{
box(78,24,2,1);
box(70,9,52,5);
box(77,23,30,15);
gotoxy(50,15);
printf("Play Like This");
gotoxy(31,16);
printf("1.Choose a two digit number and add the digits");
gotoxy(31,17);
printf("2.Subtract the sum from original number");
gotoxy(31,18);
printf("3.See the symbol opposit to the number you got");
gotoxy(31,19);
printf("4.Press any key The MIND READER will ");
gotoxy(31,20);
printf(" display the symbol you got");
gotoxy(31,21);
printf("5.For Best Results Please don't Turn your ");
gotoxy(31,22);
printf(" Eyes from the screen");
}
void ran()
{
time_t t;
int r,i;
int a[]={1,2,3,4,5,6,14,15,16,17,18,19,20,21,22,23,24,25,27,29,
30,33,34,35,36,37,38,40,41,42,43,60,62,61,63,64,123,124,
125,126,127,128,154,155,156,171,172,174,175,229,234,235,
236,237,238,239, 240,242,243,244,245,246,247,251,254};
srand((unsigned) time(&t));
r=rand() % 65;
help();
textcolor(10);
gotoxy(50,2);
cprintf("MAIND READER");
for(i=1;i<23;i++)
{
textcolor(13);
gotoxy(3,i+1);
cprintf("%d->%c ",i,a[rand()%65]);
gotoxy(10,i+1);
cprintf("%d->%c ",i+22,a[rand()%65]);
gotoxy(17,i+1);
cprintf("%d->%c ",i+44,a[rand()%65]);
gotoxy(24,i+1);
cprintf("%d->%c ",i+66,a[rand()%65]);
}
fun(3,10,9,r);
fun(3,19,18,r);
fun(10,6,27,r);
fun(10,15,36,r);
fun(17,2,45,r);
fun(17,11,54,r);
fun(17,20,63,r);
fun(24,7,72,r);
fun(24,16,81,r);
for(i=1;i<12;i++)
{
gotoxy(31,i+1);
cprintf("%d->%c ",i+88,a[rand()%65]);
}
gotoxy(55,7);
textcolor(15+BLINK);
cprintf("Press Any Key");
getch();
gotoxy(55,7);
textcolor(BLACK);
cprintf("Press Any Key");
gotoxy(61,7);
textcolor(15+BLINK);
cprintf("%c",r);
}
void main()
{
int i;
clrscr();
ran();
getch();
}
Bouncing Ball:#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <time.h>
void fun(int x,int y,int n,int a)
{
textcolor(13);
gotoxy(x,y);
cprintf("%d->%c",n,a);
}
void box(int c,int r,int s,int y)
{
int i ;
textcolor(3);
gotoxy(s,y);
cprintf("%c",218);
for(i=s+1;i<c+1;i++)
{
gotoxy(i,y);
cprintf("%c",196);
}
for(i=s+1;i<c+1;i++)
{
gotoxy(i,r);
cprintf("%c",196);
}
gotoxy(c,y);
cprintf("%c",191);
for(i=y+1;i<r;i++)
{
gotoxy(s,i);
cprintf("%c",179);
}
for(i=y+1;i<r;i++)
{
gotoxy(c,i);
cprintf("%c",179);
}
gotoxy(s,i);
cprintf("%c",192);
gotoxy(c,i);
cprintf("%c",217);
}
void help()
{
box(78,24,2,1);
box(70,9,52,5);
box(77,23,30,15);
gotoxy(50,15);
printf("Play Like This");
gotoxy(31,16);
printf("1.Choose a two digit number and add the digits");
gotoxy(31,17);
printf("2.Subtract the sum from original number");
gotoxy(31,18);
printf("3.See the symbol opposit to the number you got");
gotoxy(31,19);
printf("4.Press any key The MIND READER will ");
gotoxy(31,20);
printf(" display the symbol you got");
gotoxy(31,21);
printf("5.For Best Results Please don't Turn your ");
gotoxy(31,22);
printf(" Eyes from the screen");
}
void ran()
{
time_t t;
int r,i;
int a[]={1,2,3,4,5,6,14,15,16,17,18,19,20,21,22,23,24,25,27,29,
30,33,34,35,36,37,38,40,41,42,43,60,62,61,63,64,123,124,
125,126,127,128,154,155,156,171,172,174,175,229,234,235,
236,237,238,239, 240,242,243,244,245,246,247,251,254};
srand((unsigned) time(&t));
r=rand() % 65;
help();
textcolor(10);
gotoxy(50,2);
cprintf("MAIND READER");
for(i=1;i<23;i++)
{
textcolor(13);
gotoxy(3,i+1);
cprintf("%d->%c ",i,a[rand()%65]);
gotoxy(10,i+1);
cprintf("%d->%c ",i+22,a[rand()%65]);
gotoxy(17,i+1);
cprintf("%d->%c ",i+44,a[rand()%65]);
gotoxy(24,i+1);
cprintf("%d->%c ",i+66,a[rand()%65]);
}
fun(3,10,9,r);
fun(3,19,18,r);
fun(10,6,27,r);
fun(10,15,36,r);
fun(17,2,45,r);
fun(17,11,54,r);
fun(17,20,63,r);
fun(24,7,72,r);
fun(24,16,81,r);
for(i=1;i<12;i++)
{
gotoxy(31,i+1);
cprintf("%d->%c ",i+88,a[rand()%65]);
}
gotoxy(55,7);
textcolor(15+BLINK);
cprintf("Press Any Key");
getch();
gotoxy(55,7);
textcolor(BLACK);
cprintf("Press Any Key");
gotoxy(61,7);
textcolor(15+BLINK);
cprintf("%c",r);
}
void main()
{
int i;
clrscr();
ran();
getch();
}
========================================================
#include<graphics.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>
#include<stdlib.h>
void *ball;
void image()
{
//ball
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(10,10,10,10);
ball=malloc(imagesize(0,0,20,20));
getimage(0,0,20,20,ball);
cleardevice();
}
void main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"");
int l=getmaxx()/2,r=0,t=0,b=0;
int x=1,y=1;
int s=0,key=0;
int xstep=1,ystep=1;
image();
setbkcolor(GREEN);
while(key!=27)
{
while(!kbhit()){
putimage(l,t,ball,XOR_PUT);
delay(5);
putimage(l,t,ball,XOR_PUT);
if(l>=getmaxx()||l<=0){x*=-1;sound(1000);s=0;xstep=x*(random(4)+1);ystep=y
*(random(3)+1);if(l<=0)l=0;else l=getmaxx();}
if(t>=getmaxy()||t<=0){y*=-1;sound(1000);s=0;ystep=y*(random(4)+1);xstep=x
*(random(3)+1);if(t<=0)t=0;else t=getmaxy();}
l+=x+xstep;
t+=y+ystep;
s++;
if(s==5)
{nosound();}
}
key=getch();
}
closegraph();
}
========================================================
Conversion of Decimal to Binary:
#include <stdio.h>
void dec_bin(int number);
int main(void) {
int input = 0;
printf("Digit (0-255): ");
scanf("%d", &input);
(input >= 0) && (input < 256) ? dec_bin(input) : exit(1);
return 0;
}
void dec_bin(int number) {
int x, y;
x = y = 0;
for(y = 7; y >= 0; y--) {
x = number / (1 << y);
number = number - x * (1 << y);
printf("%d", x);
}
printf("\n");
}
=============================================================
Guessing Number Game:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void) {
int mine = 0;
int yours = 0;
srand(time(NULL));
mine = 1 + rand() % 10;
printf("Guess my number, 1 - 10: ");
scanf("%d", &yours);
if(yours < mine)
printf("Your guess was to low\n");
else if(yours > mine)
printf("Your guess was to high\n");
else
printf("Yesss ... you got it!\n");
printf("The correct number was, %d\n", mine);
return 0;
}
=============================================================
Prime Number:
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
int isprime(int value);
int main(int argc, char *argv[]) {
int number = 0;
if(argc != 2) {
fprintf(stderr, "Usage: isprime INT\n");
return 1;
} else
number = atoi(argv[1]);
if(isprime(number) == 0)
printf("%2d is NO prime\n", number);
else
printf("%2d is a prime...\n", number);
return 0;
}
int isprime(int value) {
int retval = -1;
int i = 0;
for(i = 2; i <= value / 2; i++) {
if(value % i == 0) {
retval = 0;
break;
}
}
return retval;
}
==========================================================
Calculate Height of Tree:
#include <stdio.h>
#include <error.h>
#include <stdlib.h>
#include <math.h>
/* 1 degrees = 0.0174532925 radians */
#define ONEDEGREE 0.0174532925
int main(int argc, char *argv[]) {
double base = 0;
double degrees = 0;
double radians = 0;
if(argc != 3)
error(1, 0, "base degrees");
else {
base = strtod(argv[1], (char **)NULL);
degrees = strtod(argv[2], (char **)NULL);
}
/* convert degrees to radians */
radians = degrees * ONEDEGREE;
printf("base : %.2f\n", base);
printf("degrees : %.2f\n", degrees);
printf("radians : %.2f\n", radians);
printf("tan : %.2f\n", tan(radians));
printf("height : %.2f * %.2f = %.2f\n", base, tan(radians), (base * tan(radians)));
return 0;
}
==========================================================
Tossing Coin Game (Head or Tail):
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void) {
int coin = 0;
int guess = 0;
srand(time(NULL));
coin = rand() % 2;
printf("Your call ... 0 = head, 1 = tail: ");
scanf("%d", &guess);
if(coin == guess)
printf("You called it correctly ... !\n");
else
printf("No way ... !\n");
return 0;
}
============================================================