Wednesday, 11 June 2014

stack implementation using Linked List In C Programing

#include<stdio.h>
#include<conio.h>
void push_stack ();
void pop_stack ();
void display_stack ();

typedef struct node
{
int data_stack ;
struct node *link;
}d;
d*top=NULL;


main()
{
int d;
printf("\tMENU\n1.PUSH_STACK \n2.POP_STACK \n3.DISPLAY_STACK \n4.EXIT\n");
do
{
printf("\nEnter your choice\n");
scanf("%d",&d);
switch(d)
{
case 1:
push_stack ();
break;
case 2:
pop_stack ();
break;
case 3:
display_stack ();
break;
case 4:
break;
default:
printf("Invalid choice\n");
break;
}
}
while(d!=4);
}


void push_stack ()
{
int item;
d *temp;
printf("Enter the item\n");
scanf("%d",&item);
temp=(d*)malloc(sizeof(d));
temp->data_stack =item;
temp->link=top;
top=temp;
}

void pop_stack ()
{
d *temp;
if(top==NULL)
printf("Stack is empty\n");
else
{
temp=top;
printf("The element deleted = %d\n",temp->data_stack );
top=top->link;

free(temp);
}
}

void display_stack ()
{
d *save;
if(top==NULL)
printf("Stack is empty\n");
else
{
save=top;
printf("The elements of the stack are :");
while(save!=NULL)
{
printf("%d\t",save->data_stack );
save=save->link;
}
printf("\nTopmost element = %d\n",top->data_stack );
}
}

Create Stack And Insert Data Using C Programming

#include<stdio.h>
#include<conio.h>
#define col 4
#define row 4

void main()
{
            int i,n,j;
            float ax[row+1], ay[col+1],diff[row+1][col+1],x,p,ya1,ya2,ya3,ya4,ya,ha;

            clrscr();

            printf("Enter thae value of n:");
            scanf("%d",&n);

            printf("\n Enter thae values of X and Y:\n");
            for(i=0; i<=n; i++)
            {
                        scanf("%f %f",&ax[i],&ay[i]);
            }

            printf("Value of X:");
            scanf("%f",&x);

            ha=ax[1]-ax[0];

            for(i=0; i<=n-1; i++)
                        diff[i][1]=ay[i+1]-ay[i];
            for(j=2; j<=row; j++)
                        for(i=0; i<=n-j; i++)
                                    diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

            p=(x-ax[0])/ha;
            ya1=p*diff[0][1];
            ya2=p*(p-1)*diff[0][2]/2;
            ya3=p*(p-1)*(p-2)*diff[0][3]/6;
            ya4=p*(p-1)*(p-2)*(p-3)*diff[0][4]/24;
            ya=ay[0]+ya1+ya2+ya3+ya4;
            printf("%f",ya);
            getcha();



}

Create Stack Using C Programming

#include<stdio.h>
#include<conio.h>
#define col 4
#define row 4

void main()
{
            int i,n,j;
            float ax[row+1], ay[col+1],diff[row+1][col+1],x,p,ya1,ya2,ya3,ya4,ya,ha;

            clrscr();

            printf("Enter thae value of n:");
            scanf("%d",&n);

            printf("\n Enter thae values of X and Y:\n");
            for(i=0; i<=n; i++)
            {
                        scanf("%f %f",&ax[i],&ay[i]);
            }

            printf("Value of X:");
            scanf("%f",&x);

            ha=ax[1]-ax[0];

            for(i=0; i<=n-1; i++)
                        diff[i][1]=ay[i+1]-ay[i];
            for(j=2; j<=row; j++)
                        for(i=0; i<=n-j; i++)
                                    diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

            p=(x-ax[0])/ha;
            ya1=p*diff[0][1];
            ya2=p*(p-1)*diff[0][2]/2;
            ya3=p*(p-1)*(p-2)*diff[0][3]/6;
            ya4=p*(p-1)*(p-2)*(p-3)*diff[0][4]/24;
            ya=ay[0]+ya1+ya2+ya3+ya4;
            printf("%f",ya);
            getcha();



}

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);
}
}