Showing posts with label C program. Show all posts
Showing posts with label C program. Show all posts

Monday, November 9, 2009

This is game...

#include "stdio.h"
#include "ctype.h"
#include "alloc.h"
#include "graphics.h"
#include "dos.h"
#include "stdlib.h"
#include "conio.h"

#define n 25
void start(void);
void end(void);
void rhits(void);
void yhits(void);
void phits(void);
char *msg;
void *ball, *ball1, *ball2, *gun, *bomb[n];

void *rhrt[n], *yhrt[n], *phrt[n];
int rflag[n], yflag[n], pflag[n];
int rx[n], ry[n], yx[n], yy[n], px[n], py[n];
int j, life = 3;
int rin=0, yin=0, pin=0;
unsigned int size,size1,size2,size3,size4;
int count = 0, r = 10, bct=0;
int nohits = 0, i;
int ats = 0;
int xend = 400, yend = 450;
char che = 3, ch;
int flag = 1, x = 5, gx = 4, hitflag[n];
int speed = 1, hity[n], hitx[n];
int x1 = 200, x2 = 377;
int ti=500;
int flag1 = 1, flag2 = 1;
int rhit = 0, yhit = 0, phit = 0;
struct time t;

void main(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\tc\bgi");

sprintf(msg,"%c",che);

setcolor(RED);
settextstyle(0,0,30);
outtextxy(getmaxx()/2-130,getmaxy()/2-100,msg);

setcolor(WHITE);
settextstyle(0,0,0);
outtextxy(getmaxx()/2-100,getmaxy()/2-50,"Heart Break Kid Game");
outtextxy(getmaxx()/2-100,getmaxy()/2,"From Prashanth Babu T");

getch();

cleardevice();

start();
for(i=0;i=15)
gx -= 15;
}
else if(ch==77)
{
if(gx<=xend-25) gx += 15; } putimage(gx,yend-14,gun,XOR_PUT); if(ch==72&&life>0)
{
ats += 1;
int remflag = 0;
for(i=0;i1)
{
hitflag[i]= 1;
remflag = 1;
hitx[i] = gx + 8 - 3;
hity[i] = yend - 14 - 15;
putimage(hitx[i],hity[i],bomb[i],XOR_PUT);
break;
}
}
if(remflag==0)
{
for(i=0;i=x&&hitx[i]<=x+20&&hity[i]>=5&&hity[i]<=25) { rhits(); count += 3; rhit += 1; hitflag[i] = 2; } if(hitx[i]>=x1&&hitx[i]<=x1+20&&hity[i]>=150&&hity[i]<=170) { yhits(); count += 2; yhit+=1; hitflag[i] = 2; } if(hitx[i]>=x2&&hitx[i]<=x2+20&&hity[i]>=250&&hity[i]<=270) { phits(); count += 1; phit+=1; hitflag[i] = 2; } if(hity[i]<=2) { hitflag[i] = 2; } if(hitflag[i]==1) { putimage(hitx[i],hity[i],bomb[i],XOR_PUT); } } if(ti>=500)
{
gettime(&t);
sprintf(msg," Current Time:%2d:%02d:%02d",t.ti_hour, t.ti_min,
t.ti_sec);

setfillstyle(1,12);
bar(xend+3,yend+3,getmaxx()-4,getmaxy()-4);
setcolor(BLACK);
settextstyle(0,0,0);

outtextxy(xend+15,yend+10,msg);
ti = 0;
}


putimage(x,5,ball,XOR_PUT);
putimage(x1,150,ball1,XOR_PUT);
putimage(x2,250,ball2,XOR_PUT);

if(flag==1)
x += speed;
else
x -= speed;

if(x>=xend-23)
{
flag = 0;
}
if(x<=1) { flag = 1; } if(flag1==1) x1 += 1+speed; else x1 -= 1+speed; if(x1>=xend-23)
{
flag1 = 0;
}
if(x1<=1) { flag1 = 1; } if(flag2==1) x2 += 2+speed; else x2 -= 2+speed; if(x2>=xend-23)
{
flag2 = 0;
}
if(x2<=1) { flag2 = 1; } putimage(x,5,ball,XOR_PUT); putimage(x1,150,ball1,XOR_PUT); putimage(x2,250,ball2,XOR_PUT); for(i=0;i=gx-5&&rx[i]<=gx+20&&ry[i]>=yend-15&&ry[i]<=yend-5) { // count -= 3; rflag[i] = 2; life--; } } } for(i=0;i=gx-5&&yx[i]<=gx+20&&yy[i]>=yend-15&&yy[i]<=yend-5) { // count -= 2; yflag[i] = 2; life--; } } } for(i=0;i=gx-5&&px[i]<=gx+20&&py[i]>=yend-15&&py[i]<=yend-5) { // count -= 1; pflag[i] = 2; life--; } } } for(i=0;i=yend-5)
{
rflag[i] = 2;
}

for(i=0;i=yend-5)
{
yflag[i] = 2;
}


for(i=0;i=yend-5)
{
pflag[i] = 2;
}


for(i=0;i=30) speed = 2;
if(count>=60) speed = 3;
if(count>=90) speed = 4;
if(count>=120) speed = 5;

delay(12-speed);
ti += 12-speed;
}
}
void end(void)
{
char m[3];
sprintf(m,"%c",3);
clrscr();
cleardevice();
restorecrtmode();
textattr(11);

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
gotoxy(20,3);
cprintf("THE SCORE BOARD FOR HEART BREAK KID");
printf("
");

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
gotoxy(20,7);
textattr(11);
cprintf("TOTAL NUMBER OF FIRE SHOOTED : %d",ats);
gotoxy(20,9);
cprintf("TOTAL NUMBER OF POINTS SCORED : %d",count);
gotoxy(20,11);
textattr(RED);
cprintf("TOTAL NUMBER OF HITS TO RED HEART : %d",rhit);
gotoxy(20,13);
textattr(YELLOW);
cprintf("TOTAL NUMBER OF HITS TO YELLOW HEART : %d",yhit);
gotoxy(20,15);
textattr(12);
cprintf("TOTAL NUMBER OF HITS OT PINK HEART : %d",phit);
printf("
");
textattr(11);

cprintf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
getch();
/* int gd=DETECT, gm;
initgraph(&gd,&gm,"c:\tc\bgi");
while(!kbhit())
{
setcolor(random(getmaxcolor()));
settextstyle(0,0,1);
outtextxy(random(getmaxx()),random(getmaxy()),m);
setcolor(12);
settextstyle(0,0,2);
outtextxy(100,250,"THANK YOU FOR PLAYING HBK");
}
closegraph();
restorecrtmode();*/
exit(0);
}
void start(void)
{
cleardevice();
settextstyle(10,0,3);
setcolor(12);
outtextxy(150,100,"HEART BREAK KID");
settextstyle(0,0,2);
outtextxy(200,200,"DEVELOPED BY");
settextstyle(0,0,1);
outtextxy(220, 250,"Mr. Prashanth Babu T");
outtextxy(230, 270,"Vth Semester B.C.A");
outtextxy(140, 300,"PADMASHREE INSTITUTE OF INFORMATION SCIENCES");
outtextxy(230,170,"Demo Version.007");
getch();
cleardevice();
}
void rhits(void)
{
int rflg = 0;
for(j=0;j1)
{
rflag[j] = 1;
rflg = 1;
rx[j] = x-1;
ry[j] = 26;
putimage(rx[j],ry[j],rhrt[j],XOR_PUT);
break;
}
}
if(rflg==0)
{
rflag[rin] = 1;
settextstyle(0,0,1);
setcolor(RED);
sprintf(msg,"%c",che);
outtextxy(x,28,msg);
size2 = imagesize(x-1,28-2,x+8,34);
rhrt[rin] = malloc(size2);
getimage(x-1,28-2,x+8,34,rhrt[rin]);
rx[rin] = x-1;
ry[rin] = 26;
for(j=0;j1)
{
yflag[j] = 1;
yflg = 1;
yx[j] = x1-1;
yy[j] = 171;
putimage(yx[j],yy[j],yhrt[j],XOR_PUT);
break;
}
}
if(yflg==0)
{
yflag[yin] = 1;
settextstyle(0,0,1);
setcolor(YELLOW);
sprintf(msg,"%c",che);
outtextxy(x1,171,msg);
size3 = imagesize(x1-1,171,x1+8,179);
yhrt[yin] = malloc(size3);
getimage(x1-1,171,x1+8,179,yhrt[yin]);
yx[yin] = x1-1;
yy[yin] = 171;
for(j=0;j1)
{
pflag[j] = 1;
pflg = 1;
px[j] = x2-1;
py[j] = 281;
putimage(px[j],py[j],phrt[j],XOR_PUT);
break;
}
}
if(pflg==0)
{
pflag[pin] = 1;
settextstyle(0,0,1);
setcolor(12);
sprintf(msg,"%c",che);
outtextxy(x2,281,msg);
size4 = imagesize(x2-1,281,x2+8,289);
phrt[pin] = malloc(size4);
getimage(x2-1,281,x2+8,289,phrt[pin]);
px[pin] = x2-1;
py[pin] = 281;
for(j=0;j if(pflag[j]==0)
{
pin = j;
break;
}
}
}

Monday, October 26, 2009

PROGRAM TO FIND THE SOLUTION OF ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE SOLUTION OF
// ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNCX(y,z) (17-y+2*z)/20
#define FUNCY(x,z) (-18-3*x+z)/20
#define FUNCZ(x,y) (25-2*x+3*y)/20
void main()
{
float x1,y1,z1;
float a,b,c;
float x2,y2,z2;
int itr=1;
clrscr();
printf("\n\t\t\t GAUSS - SEIDEL ITERATION METHOD");
printf("\n\t\t\t=================================\n");
printf("\n\t\t\tValue Of X\t Value of Y\tValue of Z");
printf("\n======================================================");
x1=y1=z1=0;
do
{
a=FUNCX(y1,z1);
x2=x1;
x1=a;
b=FUNCY(x1,z1);
y2=y1;
y1=b;
c=FUNCZ(x1,y1);
z2=z1;
z1=c;
printf("\n Iterration : %d \t %f\t %f\t%f ",itr++,a,b,c);
}while(a!=x2 && b!=y2 && c!=z2);
printf("\n =====================================================");
printf("\n SOLUTION IS : \n\n X = %f \t Y= %f\t Z= %f",a,b,c);
getch();
}

Saturday, October 24, 2009

PROGRAM TO FIND THE ROOT OF AN EQUATION USING REGULA-FALSE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE ROOT OF AN EQUATION
// USING REGULA-FALSE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNC(x) x*x*x-4*x-9

void roots(float x1,float x2)
{
int itr=1;
char trmtr='F';
float a,F1,F2;
do{
F1=FUNC(x1);
F2=FUNC(x2);
a=(x1*F2-F1*x2)/(F2-F1);
if(FUNC(a)<0) x1=a; else x2=a; printf("\n Iterration : %d \t\t %f\t\t %f ",itr,a,FUNC(a)); if(fabs(FUNC(a))<0.0001) { printf("\n=============================================================="); printf("\n Root is : %6.4f\n",a); trmtr='T'; } else { trmtr='F'; itr++; } }while(trmtr=='F'); } void main() { float x1,x2; clrscr(); printf("\n\t\t\t\t REGULA-FALSE METHOD\n"); printf("\n Enter the initial values : "); scanf("%f%f",&x1,&x2); if(FUNC(x1)<0 && FUNC(x2)>0)
{
printf("\n\t\t\t ITERATIONS INVOLVED \n");
printf("\n\t\t\t Aprox Root(s) \t Value of Function\n");
printf("\n===============================================");
roots(x1,x2);
}
else
{
printf("\n ROOTS of the Function don't lie between %3.0f and %3.0f",x1,x2);
getch();
exit(0);
}
getch();
}

Sunday, October 18, 2009

Calender of a month of the current year....

// SHUAIB SARKAR

// PROGRAM TO DISPLAY THE CALENDER OF A GIVEN MONTH
// OF CURRENT YEAR

#include"stdio.h"
#include"conio.h"
#include"dos.h"
#include"math.h"

void main()
{
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
char *chmon[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY"
,"JUNE","JULY","AUGUST","SEPTEMBER","OCTOER",
"NOVEMBER","DECEMBER"};
int cal,mth,year,leap;
int i,day,odday=1,date;
struct date d;
clrscr();
getdate(&d);
if(d.da_year%4==0)
mon[1]=29;
do{
printf("\n Enter the Month (1-12) : ");
scanf("%d",&mth);
if(mth<=0 || mth>12)
{
textcolor(5);
cprintf("\n PLEASE Enter the correct data");
textcolor(7);
}
}while(mth<=0 || mth>12);
year=d.da_year;
for(i=0;i<(mth-1;i++)< p="">
{
odday+=mon[i]%7;
}
year-=2000;
year--;
leap=year/4;
leap+=year;
odday+=leap;
cal=odday%7;
day=cal+1;
printf("\n\n\t\t CALANDER FOR %s %d\n",chmon[mth-1],d.da_year);
printf("\n\t====================================================\n\n");
printf("\t SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n");
if(cal==1)
printf("\t");
if(cal==2)
printf("\t\t");
if(cal==3)
printf("\t\t\t");
if(cal==4)
printf("\t\t\t\t");
if(cal==5)
printf("\t\t\t\t\t");
if(cal==6)
printf("\t\t\t\t\t\t");
for(date=1;date<=mon[mth-1];date++)
{
printf("\t%3d",date);
if(day==7)
{
printf("\n\n");
day=0;
}
day++;
}
printf("\n\n\n");
getch();
}

Saturday, October 17, 2009

Program to Get the Calender of any year......

// SHUAIB SARKAR
// PROGRAM TO DISPLAY THE CALENDER OF A GIVEN YEAR

#include"stdio.h"
#include"conio.h"
#include"dos.h"
#include"math.h"

void main()
{
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
char *chmon[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOER",
"NOVEMBER","DECEMBER"};
int cal,mth,year,leap,yr;
int i,day,odday,date;
clrscr();
do{
printf("\n Enter the Year : ");
scanf("%d",&year);
if(year<1901
year>2099)
{
textcolor(5);
cprintf("\n Please enter the year from 1901 to 2099");
textcolor(7);
}
}while(year<1901
year>2099);
if(year%4==0)
mon[1]=29;
for(mth=1;mth<=12;mth++)
{
clrscr();
odday=1;
yr=year;
yr--;
if(yr>=2000)
yr-=2000;
else
if(yr<2000)
{
yr-=1600;
yr%=300;
odday=2;
}
leap=yr/4;
leap+=yr;
odday+=leap;
for(i=1;i<=mth;i++)
{
odday+=mon[i-2]%7;
}
cal=odday%7;
day=cal+1;
textcolor(4);
cprintf("\n\n\n\n CALANDER FOR %s %d\n",chmon[mth-1],year);
textcolor(7);
printf("\n\t====================================================\n\n");
printf("\t SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n");
if(cal==1)
printf("\t");
if(cal==2)
printf("\t\t");
if(cal==3)
printf("\t\t\t");
if(cal==4)
printf("\t\t\t\t");
if(cal==5)
printf("\t\t\t\t\t");
if(cal==6)
printf("\t\t\t\t\t\t");
for(date=1;date<=mon[mth-1];date++)
{
printf("\t%3d",date);
if(day==7)
{
printf("\n\n");
day=0;
}
day++;
}
getch();
}
}

Thursday, October 15, 2009

A N- Queen Problem Solution.......

Description : This is NQueens' problem. Here n queens will have to be placed in (n x n) matrix in such a way that none will meet any other wile moving horizontally, vertically or along diagonal with respect to its position. The program is able to take any input, but for better output try it with not more than 23.


/*@@ Problem : This is n-Queen problem.

@@ Description : To place n queens in (n x n) matrix such that no queen meets another while moving    along the row, col or diagonal with respect to to its position.

@@ Done by : Biswajit Debnath.

@@ University : RajaBazar Science College(Calcutta University), Kolkata

@@ E-mail : biswajitdebnathrbsc@yahoo.co.in

*/
THIS PROGRAM IS WRITTEN BY Mr. BISWAJEET DEBANTH....


#include "iostream.h"

#include "ctype.h"

#include "stdlib.h"

#include "stdio.h"

#include "conio.h"

void check(int, int, char [100][100]);
void print(char [100][100]);
int no_of_queens, queen = 2, flagrow = 0, flagcol = 0;
int count = 1;
char ch, response_row, response_col;
int main(void)
{
int row, col, i;
char board[100][100], response;
clrscr();
printf(" This is n-queen problem.Enter the number of
queens(say n)
and watch how computer places them
in (n x n) matrix
such that none can
meet another moving along horizontally,
vertically
or digonally.");

printf("Enter the number of queens : ");
scanf("%d", &no_of_queens);
if(no_of_queens > 23)
{
printf("Thought the program is OK for any queen value.But
due the configuration of the output screen the output will be
tranketed (A very large queen number may cause the system stackoverflow).
So it is highly recommended that you run the program withmaximum queen number 23...");

printf("Want to continue(Y/N)?");
fflush(stdin);
scanf("%c", &response);
if(toupper(response) == 'N')
return (0);
}
else
 if(no_of_queens < 3)
{
printf("The number of Queen must be greater than 3.");
getch();
return (0);
}
printf("Want a row number below the board(Y/N) : ");
fflush(stdin);
response_row = (char)getchar();
if(toupper(response_row) == 'Y')
flagrow = 1;
printf("Want a column number below the board(Y/N) : ");
fflush(stdin);
response_col = (char)getchar();
if(toupper(response_col) == 'Y')
flagcol = 1;
clrscr();
printf("M/c in work ! Please Wait...");
// This for-loop is used for checking all the columns of row 0 only...
_setcursortype(_NOCURSOR);
for(col = 0; col < no_of_queens; col++)
{
memset(board, '-', sizeof(board));
check( 0, col, board );
}
clrscr();
printf("Thank you for seeing this program through.");
getch();
return (0);
}
void check( int r, int c, char board[100][100] )
{
int i, j;
// Terminating condition for the recursion...
if ( ( r == no_of_queens ) && ( c == 0 ))
{
clrscr();
printf(" (%d-Queen) Set : %d
, no_of_queens, count++);
print( board );
fflush(stdin);
ch = (char)getch();
clrscr();
if(ch == 'e')
exit (0);
printf("M/c in work ! Please Wait...");
}
// Vertical check...
for(i = 0; i < r; i++)
{
if ( board[i][c] == queen)
return;
}
// Horizontal check...
for(j = 0; j < c; j++)
{
if ( board[r][j] == queen)
return;
}
// Left-Diagonal check...
i = r; j = c;
do
{
if ( board[i][j] == queen )
return;
i--; j--;
}
while( i >= 0 && j >= 0 );
// Right-Diagonal check...
i = r; j = c;
do
{
if ( board[i][j] == queen )
return;
i--; j++;
}while( i >= 0 && j < no_of_queens );

// Placing the queen if the ckecked position is OK...
board[r][c] = queen;
r++;
// This for-loop is used for checking all the columns for each row
//starting from 1 upto the end...
for(int p = 0; p < no_of_queens; p++)
check(r, p, board);
for(int h = 0; h < no_of_queens; h++)
board[r - 1][h] = '-';
}
void print(char board[100][100])
{
for(int i = 0; i < no_of_queens; i++)
{
if(flagrow == 1)
printf("%3d", i + 1);
for(int j = 0; j < no_of_queens; j++)
{
if(board[i][j] == queen)
{
textcolor(RED);
cprintf("%3c", queen);
}
else
{
textcolor(8); //dark gray
cprintf("%3c", 22);
}
}
printf("
);
}
textcolor(7);
if(flagcol == 1)
{
if(flagrow)
printf(" ");
for(i = 0; i < no_of_queens; i++)
printf("%3d", i + 1);
}
gotoxy(62, 1);
printf("Press E to exit.");
textcolor(7);
}

Monday, September 14, 2009

C Program for Bisection Method

Bisection method:
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "iostream.h"
 
int fn[20];
int n;
double a,b,x0;
double fnval;
 
float abso(float x)
{
        if (x<0) return -x;else return x;
}
 
double power(double a,int b)
{
        int i;
        double c=1;
        for (i=0;i<=b;i++)
c=c*a;
        return c;
}
 
void getfunction()
{
        int i;
        printf("Enter the degree of the function: ");
        cin >> n;
        printf("\nStart entering the coefficients\n\n");
        for (i=n;i>=0;i--)
        {
               printf("Enter coefiicient of degree %d: ",i);
               cin >> fn[i];
        }
}
 
void displayfunction()
{
        int i;
        printf("\nCurrent function is:\n ");
        for (i=n;i>-1;i--)
        {
               if (i==0) printf("%d",fn[i]);
               else printf("%dx^%d + ",fn[i],i);
        }
}
 
float getaccuracy()
{
        float no;
        printf("\nEnter the accuracy required: ");
        cin >> no;
        return no;
}
 
double fx(double x)
{
        int i;
        double ans=0;
        for (i=n;i>-1;i--)
        {
               ans=ans+fn[i]*power(x,i);
        }
        return ans;
}
 
void getinitialvals()
{
        float curr=0,prev=0;
        static float left=-100;
        for (int i=left;i<=100;i++)
        {
               curr=fx(i);
               a=i-1;b=i;
               if (curr==0)
               {
                       left=i+1;
                       printf("\nroot is %f",b);
                       getinitialvals();
               }
 
               if (i==99)
               {
                       printf("\n\nThe equation has no further real roots");
                       exit(1);
               }
 
               if (curr*prev<0)
               {
                       left=i;
                       break;
               }
               prev=curr;
        }
}
 
void checkinivals()
{
        if(fx(a)>fx(b))
        {
               double temp=a;
               a=b;
               b=temp;
        }
}
 
 
int main()
{
        int i=0,itr=0;
        int j=1;
        clrscr();
        getfunction();
        float accu=getaccuracy();
        displayfunction();
        do
        {
               i=0;
               getinitialvals();
               checkinivals();
               cout << "\n\nInitial values are "<< a<< " and " << b << "\n";
               do
               {
                       x0=(a+b)/2;
                       fnval=fx(x0);
                       printf("%d%15f%15f%15f%15f%15f\n",i+1,a,b,x0,fnval,b-a);
                       if (fnval<0) a=x0; else b=x0;
                       i++;
               } while (abso(b-a)>accu);
 
               printf("\n\nThe root of the equation is %f in %d iterations",x0,i);
               printf("\nPress any key to search for more roots");
               getch();
 
        } while(1);
}

C Program to Maintain a Small Library

#include"stdio.h"
#include"conio.h"
#include"string.h"
#include"math.h"
struct library
{
            int acc_no;
            char title[20];
            char author[15];
            int price;
            char flag;
};
struct library book[200];
int count,i=0;
int menu()
{
            int opt;
            printf("\n 1. Add Book Information\n 2. Display Book Information");
            printf("\n 3. List all Books of a Given Author\n 4. List the Title of a Specified Book");
            printf("\n 5. List the count of Books in the Library");
            printf("\n 6. List the Books in the Order of Accession No.");
            printf("\n 7. Exit");
            printf("\n Please Enter Your Option : ");
            scanf("%d",&opt);
            return opt;
}
void add()
{
            char ch;
            do{
            printf("\n --**:: Enter the Information of a New Book ::**--");
            printf("\n Accession no.                      : ");
            scanf("%d",&book[i].acc_no);
            printf("\n Title                        : ");
            scanf("%s",book[i].title);
            printf("\n Name of Author                              : ");
            scanf("%s",book[i].author);
            printf("\n Price of the Book                : ");
            scanf("%d",&book[i].price);
            fflush(stdin);
            printf("\n Has the book been Issued? : ");
            scanf("%c",&book[i].flag);
            fflush(stdin);
            textcolor(4);
            cprintf("\n\n Do you want to add another book (y/n) : ");
            textcolor(7);
            scanf("%c",&ch);
            count=i+1;
            i++;
            }while(ch=='y' || ch=='Y');
}
void display()
{
            int i;
            for(i=0;i
            {
                        printf("\n\n <---------------Book No. %d----------------->\n",i+1);
                        printf("\n Name                                   : %s",book[i].title);
                        printf("\n Author                     : %s",book[i].author);
                        printf("\n Accession No.        : %d",book[i].acc_no);
                        printf("\n Price                        : %d",book[i].price);
                        printf("\n Issued (STATUS)   : %c",book[i].flag);
            }
}
void searchau()
{
            char name[15];
            int i,cnt=0;
            printf("\n Enter the Author name to Search : ");
            scanf("%s",name);
            for(i=0;i
            {
                        if(strcmp(name,book[i].author)==0)
                                    printf("\n Book %d  : %s",++cnt,book[i].title);
            }
            if(cnt==0)
                        printf("\n NO RECORD FOUND\n");
            }
void searchacc()
{
            int i,acc,found=0;
            printf("\n Enter the Accession no. to Search the Book : ");
            scanf("%d",&acc);
            for(i=0;i
            {
                        if(acc==book[i].acc_no)
                        {
                                    printf("\n\n Book Title : %s",book[i].title);
                                    found=1;
                        }
            }
            if(found==0)
                        printf("\n NO RECORD FOUND");
}
void main()
{
            int opt;
            char ch;
            do{
            clrscr();
            opt=menu();
            switch(opt)
            {
                        case 1:
                           add();
                           break;
                        case 2:
                           display();
                           break;
                        case 3:
                           searchau();
                           break;
                        case 4:
                           searchacc();
                           break;
                        case 5:
                           printf("\n The Total No. of Books in Library is : %d",count);
                           break;
                        case 6:
                           display();
                           break;
                        default:
                           exit(0);
            }
            fflush(stdin);
            printf("\n Do you want to Continue (y/n) : ");
            scanf("%c",&ch);
            }while(ch=='y' || ch=='Y');
}

Program to Multiply Two Matrices

#include "stdio.h"


#include "conio.h"

typedef int MATRIX;

void main()

{

MATRIX x[5][5],y[5][5],z[5][5];

int i,j,r,c,k;

clrscr();

do{

printf("\n Enter the no. of rows for two matrices : ");

scanf("%d",&r);

printf("\n Enter the no. of cols for two matrices : ");

scanf("%d",&c);

if(r<=0

c<=0)

printf("\n MATRIX is NOT Possible");

if(r!=c)

printf("\n MULTIPLICATION is not possible");

}while(r<=0

c<=0

r!=c);

printf("\n --**:: FIRST MATRIX ::**--");

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

printf("\n Element X(%d,%d) :",i,j);

scanf("%d",&x[i][j]);

}

}

printf("\n --**:: SECOND MATRIX ::**--");

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

printf("\n Element Y(%d,%d) :",i,j);

scanf("%d",&y[i][j]);

}

}

for(i=1;i<=r;i++)

{

for(j=1;j<=c;j++)

{

z[i][j]=0;

for(k=1;k<=r;k++)

{

z[i][j]+=x[i][k]*y[k][j];

}

}

}

printf("\n --**:: FIRST MATRIX ::**--");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",x[i][j]);

}

}

printf("\n --**:: SECOND MATRIX ::**--");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",y[i][j]);

}

}

printf("\n --**:: MULTIPLICATION DONE ::**--");

printf("\n Result is : \n");

for(i=1;i<=r;i++)

{

printf("\n");

for(j=1;j<=c;j++)

{

printf("\t%d",z[i][j]);

}

}

getch();

}

Sunday, September 13, 2009

C programm for Gauss's (Gaussian) Elimination Method

PROGRAM TO FIND THE SOLUTION OF SIMULTANIOUS ALGEBRIC EQUATIONS :
Gaussian Elimination Method
Give ur comments




#include
#include
#include
void main()

{

float x[5][5],r1[4],r2[4],r3[4];

float a,b,c;

int i,j,k;

clrscr();

printf("\n\t\t GAUSS ELIMINATION METHOD");

printf("\n\t\t==========================\n");

for(i=1;i<=3;i++)

{

printf("\n --**:: EQUATION No. : %d ::**--",i);

printf("\n --------------------------------");

for(j=1;j<=4;j++)

{

printf("\nCoeficient of %d term : ",j);

scanf("%f",&x[i][j]);

}

}

/*STEP ONE */

for(k=0;k<4;k++)

{

r1[k]=x[1][k+1]*x[2][1];

r2[k]=x[2][k+1]*x[1][1];

r2[k]=r2[k]-r1[k];

}

for(k=0;k<4;k++)

{

r1[k]=x[1][k+1]*x[3][1];

r3[k]=x[3][k+1]*x[1][1];

r3[k]-=r1[k];

}

for(k=1;k<=4;k++)

{

x[2][k]=r2[k-1];

x[3][k]=r3[k-1];

}

/*STEP TWO*/

for(k=0;k<4;k++)

{

r2[k]=x[2][k+1]*x[3][2];

r3[k]=x[3][k+1]*x[2][2];

r3[k]-=r2[k];

}



for(k=1;k<=4;k++)

x[3][k]=r3[k-1];

/*STEP 3 BACK SUBSTITUION*/

c=x[3][4]/x[3][3];

b=(x[2][4]-c*x[2][3])/x[2][2];

a=(x[1][4]-b*x[1][2]-c*x[1][3])/x[1][1];

printf("\n===================================\n");

printf("\n Solution is : \n");

printf("\n X = %6.3f\t Y = %6.3f\t Z = %6.3f",a,b,c);

getch();

}




OUTPUT