Latest Post
Ads
Tic-Tac-Toe Code
- Get link
- X
- Other Apps
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
int main()
{
char *ch;
FILE *fptr;
FILE * fp2;
char str3[100];
int i=0,e=0,j=0,q=0,temp=0,temp1=0,pt;
int n[9];
int scp1=0,scp2=0,game=0;
char a,b,c,d,e1,f,g,h,I;
char ch1,sign,sign1;
char m[4][4];
char str1[15],str2[15];
int choice,choice1,choice2;
char name,name1;
begin:
temp = 0;
temp1 = 0;
i = 0;
e = 0;
game = 0;
scp1 = 0;
scp2 = 0;
q = 0;
j = 0;
printf("\n\n\t\t 1. START GAME ");
printf("\n\n\t\t 2. VIEW SCORE ");
printf("\n\n\t\t 3. EXIT");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n\n\t SHUNYA - CHOKDI");
printf("\n");
printf("\n \n\tBoard Positions:");
printf("\n\n\t 1 | 2 | 3 ");
printf("\n\t-----|-----|-----");
printf("\n\t 4 | 5 | 6 ");
printf("\n\t-----|-----|-----");
printf("\n\t 7 | 8 | 9 ");
printf("\n\nStart Game - Press Enter to start: ");
scanf("%c",&ch1);
printf("\n\nPlayer 1 Enter Your Name: ");
gets(str1);
printf("\n\nPlayer 2 Enter Your Name: ");
gets(str2);
sn:
printf("\n%s Select your sign: X or O ",str1);
printf("\n Sign : ");
scanf("%c",&sign);
if (sign == 'X' || sign == 'x')
{
printf("\n\n %s your sign is X",str1);
printf("\n\n %s your sign is O",str2);
sign = 'X';
sign1 = 'O';
goto start;
}
else if (sign == 'O' || sign == 'o')
{
printf("\n\n %s your sign is O",str1);
printf("\n\n %s your sign is X",str2);
sign = 'O';
sign1 = 'X';
goto start;
}
else
{
printf("\nEnter Correct sign...");
goto sn;
}
start:
i=0;
e=0;
j=0;
q=0;
temp=0;
m[0][0]='-';
m[0][1]='-';
m[0][2]='-';
m[1][0]='-';
m[1][1]='-';
m[1][2]='-';
m[2][0]='-';
m[2][1]='-';
m[2][2]='-';
a = m[0][0];
b = m[0][1];
c = m[0][2];
d = m[1][0];
e1 = m[1][1];
f = m[1][2];
g = m[2][0];
h = m[2][1];
I = m[2][2];
n[0]=0;
n[1]=0;
n[2]=0;
n[3]=0;
n[4]=0;
n[5]=0;
n[6]=0;
n[7]=0;
n[8]=0;
j=0;
i=0;
game = temp1;;
if(temp1<3)
{
printf("\n\n\t Game : %d",temp1);
for (game=0;game<2;game++)
{
for(q=0;q<8;q++)
{
st1:
if ((a!='-')&&(b!='-')&&(c!='-')&&(d!='-')&&(e!='-')&&(f!='-')&&(g!='-')&&(h!='-')&&(I!='-'))
{
printf("\n\nNo winner");
temp1 = temp1 + 1;
game = temp1;
goto start;
}
i=temp;
printf("\n\n %s Enter position:",str1);
scanf("%d",&e);
temp = i;
for(i=0;i<9;i++)
{
if(n[i] == e)
{
printf("\n\nThis Position Already Used");
printf("\nPositions Used: ");
for(i=0;i<9;i++)
{
printf(" %d ",n[i]);
}
printf("\n");
q=q-1;
goto st1;
}
}
i = temp;
n[i]=e;
temp = temp + 1;
printf("\n");
if (e == 1)
{
a = sign;
goto fun;
}
else if (e == 2)
{
b = sign;
goto fun;
}
else if (e == 3)
{
c = sign;
goto fun;
}
else if (e == 4)
{
d = sign;
goto fun;
}
else if (e == 5)
{
e1 = sign;
goto fun;
}
else if (e == 6)
{
f = sign;
goto fun;
}
else if (e == 7)
{
g = sign;
}
else if (e == 8)
{
h = sign;
goto fun;
}
else if (e == 9)
{
I = sign;
goto fun;
}
else
{
printf("\n\nNot a valid number.");
goto end;
}
fun:
printf("\n\t\t %c | %c | %c ",a,b,c);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",d,e1,f);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",g,h,I);
if((a&b&c) == sign || (a&d&g) == sign || (g&h&I) == sign || (c&f&I) == sign || (a&e1&I) == sign || (c&e1&g) == sign || (b&e1&h) == sign ||(d&e1&f) == sign )
{
printf("\n\t\t\n %s Wins !!",str1);
temp1 = temp1 + 1;
game = temp1;
scp1 = scp1 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else if((a&b&c) == sign1 || (a&d&g) == sign1 || (g&h&I) == sign1 || (c&f&I) == sign1 || (a&e1&I) == sign1 || (c&e1&g) == sign1 || (b&e1&h) == sign1 ||(d&e1&f) == sign1 )
{
printf("\n\t\t\n %s Wins !!",str2);
temp1 = temp1 + 1;
game = temp1;
scp2 = scp2 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
p2:
if ((a!='-')&&(b!='-')&&(c!='-')&&(d!='-')&&(e!='-')&&(f!='-')&&(g!='-')&&(h!='-')&&(I!='-'))
{
printf("\n\nNo winner");
temp1 = temp1 + 1;
game = temp1;
goto start;
}
i=temp;
printf("\n\n %s Enter Position:",str2);
scanf("%d",&e);
q=q+1;
temp=i;
for(i=0;i<9;i++)
{
if(n[i] == e)
{
printf("\n\nThis Position Already Used");
printf("\nPositions Used: ");
for(i=0;i<9;i++)
{
printf(" %d ",n[i]);
}
printf("\n");
q=q-1;
goto p2;
}
}
i = temp;
temp = temp +1;
n[i]=e;
printf("\n");
if (e == 1)
{
a = sign1;
goto fun1;
}
else if (e == 2)
{
b = sign1;
goto fun1;
}
else if (e == 3)
{
c = sign1;
goto fun1;
}
else if (e == 4)
{
d = sign1;
goto fun1;
}
else if (e == 5)
{
e1 = sign1;
goto fun1;
}
else if (e == 6)
{
f = sign1;
goto fun1;
}
else if (e == 7)
{
g = sign1;
goto fun1;
}
else if (e == 8)
{
h = sign1;
goto fun1;
}
else if (e == 9)
{
I = sign1;
goto fun1;
}
else
{
printf("\n\nNot a valid number.");
goto end;
}
fun1:
printf("\n\t\t %c | %c | %c ",a,b,c);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",d,e1,f);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",g,h,I);
if((a&b&c) == sign || (a&d&g) == sign || (g&h&I) == sign || (c&f&I) == sign || (a&e1&I) == sign || (c&e1&g) == sign || (b&e1&h) == sign ||(d&e1&f) == sign )
{
printf("\n\t\t\n %s Wins !!",str1);
temp1 = temp1 + 1;
game = temp1;
scp1 = scp1 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else if((a&b&c) == sign1 || (a&d&g) == sign1 || (g&h&I) == sign1 || (c&f&I) == sign1 || (a&e1&I) == sign1 || (c&e1&g) == sign1 || (b&e1&h) == sign1 ||(d&e1&f) == sign1 )
{
printf("\n\t\t\n %s Wins !!",str2);
temp1 = temp1 + 1;
game = temp1;
scp2 = scp2 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else
{
goto st1;
}
}
}
}
else if (temp1 == 3)
{
FILE *fptr = fopen("sample.txt", "a+");
if (fptr == NULL)
{
printf("Could not open file");
return 0;
}
fprintf(fptr,"\n\t\tPlayer 1: %s \t\t Score: %d \n", str1,scp1);
fprintf(fptr,"\n\t\tPlayer 2: %s \t\t Score: %d \n\n", str2,scp2);
fclose(fptr);
if (scp1 > scp2)
{
printf("\n\n\t %s YOU ARE THE WINNER....!!!!!!!",str1);
}
else if (scp2 > scp1)
{
printf("\n\n\t %s YOU ARE THE WINNER....!!!!!!!",str2);
}
else
{
printf("\n\n\t GAME DRAW......... ");
}
}
else
{
goto end;
}
printf("\n\n\n\t Do You Want to Continue ? ");
printf("\n\n\t 1. HOME");
printf("\n\n\t 2. SCORE TABLE");
printf("\n\n\t 3. EXIT");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice1);
switch(choice1)
{
case 1:
goto begin;
break;
case 2:
goto scores;
break;
case 3:
goto end;
break;
}
break;
case 2:
scores:
printf(" \n\n Score Table : \n\n");
fp2 = fopen( "sample.txt" , "r");
if (fp2)
{
while(fgets(str3, 99, fp2)!=NULL)
{
printf("\t%s",str3);
}
printf("\n");
fclose(fp2);
}
printf("\n\n\t Do You Want to Continue ? ");
printf("\n\n\t 1. HOME");
printf("\n\n\t 2. EXIT");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice2);
switch(choice2)
{
case 1:
goto begin;
break;
case 2:
goto end;
break;
}
break;
case 3:
goto end;
break;
default:
printf("\n\t Enter Valid Choice : ");
goto begin;
break;
}
end:
return 0;
}
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
int main()
{
char *ch;
FILE *fptr;
FILE * fp2;
char str3[100];
int i=0,e=0,j=0,q=0,temp=0,temp1=0,pt;
int n[9];
int scp1=0,scp2=0,game=0;
char a,b,c,d,e1,f,g,h,I;
char ch1,sign,sign1;
char m[4][4];
char str1[15],str2[15];
int choice,choice1,choice2;
char name,name1;
begin:
temp = 0;
temp1 = 0;
i = 0;
e = 0;
game = 0;
scp1 = 0;
scp2 = 0;
q = 0;
j = 0;
printf("\n\n\t\t 1. START GAME ");
printf("\n\n\t\t 2. VIEW SCORE ");
printf("\n\n\t\t 3. EXIT");
printf("\n\n\t Enter Your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n\n\t SHUNYA - CHOKDI");
printf("\n");
printf("\n \n\tBoard Positions:");
printf("\n\n\t 1 | 2 | 3 ");
printf("\n\t-----|-----|-----");
printf("\n\t 4 | 5 | 6 ");
printf("\n\t-----|-----|-----");
printf("\n\t 7 | 8 | 9 ");
printf("\n\nStart Game - Press Enter to start: ");
scanf("%c",&ch1);
printf("\n\nPlayer 1 Enter Your Name: ");
gets(str1);
printf("\n\nPlayer 2 Enter Your Name: ");
gets(str2);
sn:
printf("\n%s Select your sign: X or O ",str1);
printf("\n Sign : ");
scanf("%c",&sign);
if (sign == 'X' || sign == 'x')
{
printf("\n\n %s your sign is X",str1);
printf("\n\n %s your sign is O",str2);
sign = 'X';
sign1 = 'O';
goto start;
}
else if (sign == 'O' || sign == 'o')
{
printf("\n\n %s your sign is O",str1);
printf("\n\n %s your sign is X",str2);
sign = 'O';
sign1 = 'X';
goto start;
}
else
{
printf("\nEnter Correct sign...");
goto sn;
}
start:
i=0;
e=0;
j=0;
q=0;
temp=0;
m[0][0]='-';
m[0][1]='-';
m[0][2]='-';
m[1][0]='-';
m[1][1]='-';
m[1][2]='-';
m[2][0]='-';
m[2][1]='-';
m[2][2]='-';
a = m[0][0];
b = m[0][1];
c = m[0][2];
d = m[1][0];
e1 = m[1][1];
f = m[1][2];
g = m[2][0];
h = m[2][1];
I = m[2][2];
n[0]=0;
n[1]=0;
n[2]=0;
n[3]=0;
n[4]=0;
n[5]=0;
n[6]=0;
n[7]=0;
n[8]=0;
j=0;
i=0;
game = temp1;;
if(temp1<3)
{
printf("\n\n\t Game : %d",temp1);
for (game=0;game<2;game++)
{
for(q=0;q<8;q++)
{
st1:
if ((a!='-')&&(b!='-')&&(c!='-')&&(d!='-')&&(e!='-')&&(f!='-')&&(g!='-')&&(h!='-')&&(I!='-'))
{
printf("\n\nNo winner");
temp1 = temp1 + 1;
game = temp1;
goto start;
}
i=temp;
printf("\n\n %s Enter position:",str1);
scanf("%d",&e);
temp = i;
for(i=0;i<9;i++)
{
if(n[i] == e)
{
printf("\n\nThis Position Already Used");
printf("\nPositions Used: ");
for(i=0;i<9;i++)
{
printf(" %d ",n[i]);
}
printf("\n");
q=q-1;
goto st1;
}
}
i = temp;
n[i]=e;
temp = temp + 1;
printf("\n");
if (e == 1)
{
a = sign;
goto fun;
}
else if (e == 2)
{
b = sign;
goto fun;
}
else if (e == 3)
{
c = sign;
goto fun;
}
else if (e == 4)
{
d = sign;
goto fun;
}
else if (e == 5)
{
e1 = sign;
goto fun;
}
else if (e == 6)
{
f = sign;
goto fun;
}
else if (e == 7)
{
g = sign;
}
else if (e == 8)
{
h = sign;
goto fun;
}
else if (e == 9)
{
I = sign;
goto fun;
}
else
{
printf("\n\nNot a valid number.");
goto end;
}
fun:
printf("\n\t\t %c | %c | %c ",a,b,c);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",d,e1,f);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",g,h,I);
if((a&b&c) == sign || (a&d&g) == sign || (g&h&I) == sign || (c&f&I) == sign || (a&e1&I) == sign || (c&e1&g) == sign || (b&e1&h) == sign ||(d&e1&f) == sign )
{
printf("\n\t\t\n %s Wins !!",str1);
temp1 = temp1 + 1;
game = temp1;
scp1 = scp1 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else if((a&b&c) == sign1 || (a&d&g) == sign1 || (g&h&I) == sign1 || (c&f&I) == sign1 || (a&e1&I) == sign1 || (c&e1&g) == sign1 || (b&e1&h) == sign1 ||(d&e1&f) == sign1 )
{
printf("\n\t\t\n %s Wins !!",str2);
temp1 = temp1 + 1;
game = temp1;
scp2 = scp2 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
p2:
if ((a!='-')&&(b!='-')&&(c!='-')&&(d!='-')&&(e!='-')&&(f!='-')&&(g!='-')&&(h!='-')&&(I!='-'))
{
printf("\n\nNo winner");
temp1 = temp1 + 1;
game = temp1;
goto start;
}
i=temp;
printf("\n\n %s Enter Position:",str2);
scanf("%d",&e);
q=q+1;
temp=i;
for(i=0;i<9;i++)
{
if(n[i] == e)
{
printf("\n\nThis Position Already Used");
printf("\nPositions Used: ");
for(i=0;i<9;i++)
{
printf(" %d ",n[i]);
}
printf("\n");
q=q-1;
goto p2;
}
}
i = temp;
temp = temp +1;
n[i]=e;
printf("\n");
if (e == 1)
{
a = sign1;
goto fun1;
}
else if (e == 2)
{
b = sign1;
goto fun1;
}
else if (e == 3)
{
c = sign1;
goto fun1;
}
else if (e == 4)
{
d = sign1;
goto fun1;
}
else if (e == 5)
{
e1 = sign1;
goto fun1;
}
else if (e == 6)
{
f = sign1;
goto fun1;
}
else if (e == 7)
{
g = sign1;
goto fun1;
}
else if (e == 8)
{
h = sign1;
goto fun1;
}
else if (e == 9)
{
I = sign1;
goto fun1;
}
else
{
printf("\n\nNot a valid number.");
goto end;
}
fun1:
printf("\n\t\t %c | %c | %c ",a,b,c);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",d,e1,f);
printf("\n\t\t-----|-----|-----");
printf("\n\t\t %c | %c | %c ",g,h,I);
if((a&b&c) == sign || (a&d&g) == sign || (g&h&I) == sign || (c&f&I) == sign || (a&e1&I) == sign || (c&e1&g) == sign || (b&e1&h) == sign ||(d&e1&f) == sign )
{
printf("\n\t\t\n %s Wins !!",str1);
temp1 = temp1 + 1;
game = temp1;
scp1 = scp1 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else if((a&b&c) == sign1 || (a&d&g) == sign1 || (g&h&I) == sign1 || (c&f&I) == sign1 || (a&e1&I) == sign1 || (c&e1&g) == sign1 || (b&e1&h) == sign1 ||(d&e1&f) == sign1 )
{
printf("\n\t\t\n %s Wins !!",str2);
temp1 = temp1 + 1;
game = temp1;
scp2 = scp2 + 1;
printf("\n\n\t %s your score is : %d",str1,scp1);
printf("\n\t %s your score is : %d",str2,scp2);
goto start;
}
else
{
goto st1;
}
}
}
}
else if (temp1 == 3)
{
FILE *fptr = fopen("sample.txt", "a+");
if (fptr == NULL)
{
printf("Could not open file");
return 0;
}
fprintf(fptr,"\n\t\tPlayer 1: %s \t\t Score: %d \n", str1,scp1);
fprintf(fptr,"\n\t\tPlayer 2: %s \t\t Score: %d \n\n", str2,scp2);
fclose(fptr);
if (scp1 > scp2)
{
printf("\n\n\t %s YOU ARE THE WINNER....!!!!!!!",str1);
}
else if (scp2 > scp1)
{
printf("\n\n\t %s YOU ARE THE WINNER....!!!!!!!",str2);
}
else
{
printf("\n\n\t GAME DRAW......... ");
}
}
else
{
goto end;
}
printf("\n\n\n\t Do You Want to Continue ? ");
printf("\n\n\t 1. HOME");
printf("\n\n\t 2. SCORE TABLE");
printf("\n\n\t 3. EXIT");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice1);
switch(choice1)
{
case 1:
goto begin;
break;
case 2:
goto scores;
break;
case 3:
goto end;
break;
}
break;
case 2:
scores:
printf(" \n\n Score Table : \n\n");
fp2 = fopen( "sample.txt" , "r");
if (fp2)
{
while(fgets(str3, 99, fp2)!=NULL)
{
printf("\t%s",str3);
}
printf("\n");
fclose(fp2);
}
printf("\n\n\t Do You Want to Continue ? ");
printf("\n\n\t 1. HOME");
printf("\n\n\t 2. EXIT");
printf("\n\n\t Enter your choice : ");
scanf("%d",&choice2);
switch(choice2)
{
case 1:
goto begin;
break;
case 2:
goto end;
break;
}
break;
case 3:
goto end;
break;
default:
printf("\n\t Enter Valid Choice : ");
goto begin;
break;
}
end:
return 0;
}
C Programs:
------------------------
| Pattern Programs
------------------------
- Get link
- X
- Other Apps
Ads
Popular posts from this blog
1 to 4 DEMUX (Demultiplexer) Verilog CodeStructural/Gate Level Modelling with Testbench
Verilog Code for 1 to 4 DEMUX Structural/Gate Level Modelling 1-4 DEMUX module demux_1_to_4( input d, input s0, input s1, output y0, output y1, output y2, output y3 ); not(s1n,s1),(s0n,s0); and(y0,d,s0n,s1n),(y1,d,s0,s1n),(y2,d,s0n,s1),(y3,d,s0,s1); endmodule //Testbench code for 1 to 4 DEMUX Structural/Gate Level Modelling initial begin // Initialize Inputs d = 1; s0 = 0; s1 = 0; // Wait 100 ns for global reset to finish #100; // Add stimulus here #100;d = 1;s0 = 1;s1 = 0; #100;d = 1;s0 = ...
VLSI: 2 Bit Magnitude Comparator Dataflow Modelling
module mag_comp2bit( input a0, input a1, input b0, input b1, output p, // p = (a < b) output r, // r = (a > b) output q // q = (a = b) ); assign q = ((~a1) ^ (b1)) & (a0 & b0); assign p = (((~a1) & b1) | (b0 & (~a0) & (~a1)) | ((~a0) & b1 & b0)); assign r = ((a1 & (~b1)) | ((~b0) & a1 & a0) | (a0 & (~b1) & (~b0))); endmodule
VLSI: 1-4 DEMUX (Demultiplexer) Dataflow Modelling with Testbench
Verilog Code for 1-4 DEMUX Dataflow Modelling module demux_1_to_4( input d, input s0, input s1, output y0, output y1, output y2, output y3 ); assign s1n = ~ s1; assign s0n = ~ s0; assign y0 = d& s0n & s1n; assign y1 = d & s0 & s1n; assign y2 = d & s0n & s1; assign y3 = d & s0 & s1; endmodule //Testbench code for 1-4 DEMUX Dataflow Modelling initial begin // Initialize Inputs ...
VLSI: BCD to Excess 3 and Excess 3 to BCD Dataflow Modelling
module bcd_ex3_Dataflow( input a, input b, input c, input d, output w, output x, output y, output z ); assign w = (a | (b & c) | (b & d)); assign x = (((~b) & c) | ((~b) & d) | (b & (~c) & (~d))); assign y = ((c & d) | ((~c) & (~d))); assign z = ~d; endmodule Excess 3 to BCD: module ex3_to_bcd( input w, input x, input y, input z, output a, output b, output c, output d ); assign a = ((w & x) | (w & y & z)); assign b = (((~x) & (~y)) | ((~x) & (~z)) | (x & y & z)); assign c = (((~y) & z) | (y & (~z))); assign d = ~z; endmodule
VLSI: Half Subtractor and Full Subtractor Gate Level Modelling
Half Subtractor: Verilog Module Code: module half_subtractor ( input a, input b, output diff output borr ); wire x; xor (diff,a,b); not (x,a); and (borr,x,b); endmodule Full Subtractor: Verilog Module Code: module full_subtractor ( input a, input b, input c, output diff output borr ); wire x,n2,z,n1; xor s1(x,a,b); not s3(n2,x); not s4(n1,c); and s5(y,n1,b); xor s2(diff,a,x); and s6(z,n2,a); or (borr,y,z); endmodule