Friday 2 May 2014

Quiz Game in C

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void valid()
{
printf("\n \n Correct Answer\n");
}
void invalid()
{
printf("\n \n Wrong Answer\n");
}
void wel()
{
printf("\n\n \t\t\tWelcome to the C quiz \n");
}
void note()
{
printf("\n\n\nBASIC RULES OF GAME:-");
printf("\n\n\n\t --> The quiz has 5 very basic questions of the C Programming Language.\n");
printf("\t --> Programe can accept only  digits not a character.\n");
printf("\t --> You get '+3' point for every correct answer and '-1' for every\n \t     incorrect answer.\n");
printf("\t --> you have to choose only one option from '1,2,3,4'. \n");
printf("\n\n\n\n\n");
}
void main()
{

int score=0;
int answer;
char array[10];
int x=400, y =400;
clrscr();
wel();
printf("\n\n \t\t\tEnter your name: ");
gets(array);
note();
printf("\t \t Q1) Why is it called 'C'& not 'D' ?\n");
printf("\n\n \t \t[1]C stands for code\n\n \t \t[2]The inventors name started with a C\n\n \t \t[3]It developed after a language called 'B'\n\n \t \t[4]Why should I care?\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
 {
  if(answer==3)
  {
  valid();
  score=score+3;
  }
 else
 {
 invalid();
 score=score-1;
 }
}
else
 {
 printf( "invalid\n" );
 }
delay(2000);
clrscr();
wel();
note();
printf("\n\n \t \tQ2) It was developed at?\n");
printf("\n \t \t [1]IBMt\n\n \t \t [2]Bell Labsn\n\n \t \t [3]MITt\n\n \t \t [4]Microsoft(?)\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==2)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ3) Which of these is not a C keyword as per ANSI C ?\n");
printf("\n \t \t [1]externt\n\n \t \t [2]volatilen\n\n \t \t [3]entert\n\n \t \t [4]break\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==3)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ4) What is ANSI, btw? ?\n");
printf("\n \t \t [1]Area of Natural and Scientific Interest\n\n \t \t [2]American National Standards Institute\n\n \t \t [3]American National Standardization Institute\n\n \t \t [4]American National Society Of Intellectuals\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==2)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ5)Which of these concepts is NOT supported by C ?\n");
printf("\n \t \t [1]Pointers\n\n \t \t [2]Functions\n\n \t \t [3]Strings\n\n \t \t [4]Namespaces\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==4)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();

textcolor ( 1 );
cprintf("\n\n\n\n\n\n\n\n              Thank You for taking the Quiz.");
puts(array);
printf("\n\n\n\n\t \t \tTotal Score is:- %d out of 15", score);
getch();
}

Sunday 20 April 2014

Print Syntax In Color Using C Language

#include<conio.h>
#include<stdio.h>
void yellow()
{
    textcolor ( YELLOW );
    cprintf ("YELLOW Color Testing \n");
}
void main ()
{
printf("This is BLUE COLOR");
blue();

CPRINTF Uing C

#include<conio.h>
#include<stdio.h>
void yellow()
{
    textcolor ( YELLOW );
    cprintf ("YELLOW Color Testing \n");
}
void blue()
{
    textcolor ( BLUE);
    cprintf ("Blue Color Testing \n");
}
void main ()
{
printf("This is YELLOW COLOR");
yellow();
printf("This is BLUE COLOR");
blue();

Sunday 23 March 2014

Boundary Fill Algorithm Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>

void boundryFill(int, int, int, int);
int midx=319, midy=239;

void main()
{
int gdriver=DETECT, gmode, x,y,r;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
cleardevice();
printf("Enter the Center of circle (X,Y) : ");
scanf("%d %d",&x,&y);
printf("Enter the Radius of circle R : ");
scanf("%d",&r);
circle(midx+x,midy-y,r);
getch();
boundryFill(midx+x,midy-y,13,15);
getch();
closegraph();
}
void boundryFill(int x, int y, int fill, int boundry)
{
if((getpixel(x,y)!= fill) && (getpixel(x,y) != boundry))
{
putpixel(x,y,fill);
delay(5);
boundryFill(x+1,y,fill,boundry);
boundryFill(x-1,y,fill,boundry);
boundryFill(x,y+1,fill,boundry);
boundryFill(x,y-1,fill,boundry);
}
}

Flood Fill Algorithm Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>

void flood(int,int,int);

void main()
{

int gd=DETECT,gm;
int ch,x,y,bc,fc;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
printf("Enter boundry color:");
scanf("%d",&bc);
setcolor(bc);
rectangle(250,200,300,250);
x=280;
y=240;
flood(x,y,bc);
getch();
closegraph();
}
void flood(int x,int y,int bc)
{
if(getpixel(x,y)!=bc)
{
putpixel(x,y,bc);
flood(x+1,y,bc);
flood(x,y+1,bc);
flood(x-1,y,bc);
flood(x,y-1,bc);
}
}

Thursday 6 March 2014

Tower Of Hanoi Using Backtracking in c++

#include<iostream.h>

#include<conio.h> 

void tower(int,char,char,char); 

void main()

{

int n; 

clrscr();

cout<<"enter the disk number :  ";

cin>>n;tower(n,'A','C','B'); 

getch();

void tower(int n,char from,char to,char aux)

{

if(n==1)
    {

    cout<<endl<<"move 1 from peg "<<from<<" to "<<to;return;

   }

tower(n-1,from,aux,to);

cout<<endl<<"move "<<n<<" from peg "<<from<<" to "<<to;

tower(n-1,aux,to,from);

}


Tuesday 4 March 2014

Draw Arc Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>
void main()
{
        int gd=DETECT,gm=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
       arc(110, 110, 0, 145, 55);
       /*
       arc(a,b,c,d,e);
       a= x
       b=y
       c=start angle
       d= end angle
       e=radius of arc.
       */
       getch();
       closegraph();
}