From e1da40524f0da12945d0e4cef76f5fe30eeb4d3f Mon Sep 17 00:00:00 2001 From: TushaarG Date: Fri, 25 Oct 2019 13:37:44 +0530 Subject: [PATCH 1/5] First Program --- C/.gitignore | 1 - C/Fibonacci.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 C/Fibonacci.c diff --git a/C/.gitignore b/C/.gitignore index d6b7ef3..f935021 100644 --- a/C/.gitignore +++ b/C/.gitignore @@ -1,2 +1 @@ -* !.gitignore diff --git a/C/Fibonacci.c b/C/Fibonacci.c new file mode 100644 index 0000000..7bb8143 --- /dev/null +++ b/C/Fibonacci.c @@ -0,0 +1,17 @@ +#include +int main() +{ + int a=0,b=1,c=0,i=1,n; + printf("Enter the number of terms you want to see in fibonacci \n"); + scanf("%d",&n); + printf("\n%d\n%d",a,b); + while(i<=(n-2)) + { + c=a+b; + a=b; + b=c; + printf("\n%d",c); + i++; + } + return 0; +} From 7460182fdcfd52f8a91e08cc801c144721ee4ba1 Mon Sep 17 00:00:00 2001 From: TushaarG Date: Fri, 25 Oct 2019 16:04:42 +0530 Subject: [PATCH 2/5] First --- C/Fibonacci.c | 17 ----------------- C/calci.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 C/Fibonacci.c create mode 100644 C/calci.c diff --git a/C/Fibonacci.c b/C/Fibonacci.c deleted file mode 100644 index 7bb8143..0000000 --- a/C/Fibonacci.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -int main() -{ - int a=0,b=1,c=0,i=1,n; - printf("Enter the number of terms you want to see in fibonacci \n"); - scanf("%d",&n); - printf("\n%d\n%d",a,b); - while(i<=(n-2)) - { - c=a+b; - a=b; - b=c; - printf("\n%d",c); - i++; - } - return 0; -} diff --git a/C/calci.c b/C/calci.c new file mode 100644 index 0000000..1fac38c --- /dev/null +++ b/C/calci.c @@ -0,0 +1,29 @@ +#include +int main() +{ + int a[5],i=0,s=0; + float avg=0.0; + printf("Enter five number\n"); + for(i=0;i<5;i++) + { + scanf("%d",&a[i]); + } + for(i=0;i<5;i++) + { + s=s+a[i]; + } + avg=s/5; + printf("\nThe numbers above average\n "); + for(i=0;i<5;i++) + { + if(a[i]>avg) + printf("%d\n",a[i]); + } + printf("\nThe numbers belove average\n"); + for(i=0;i<5;i++) + { + if(a[i] Date: Fri, 25 Oct 2019 16:35:55 +0530 Subject: [PATCH 3/5] Second From TG --- C/Patrun.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 C/Patrun.c diff --git a/C/Patrun.c b/C/Patrun.c new file mode 100644 index 0000000..381e53f --- /dev/null +++ b/C/Patrun.c @@ -0,0 +1,15 @@ +#include +int main() +{ + int i,j,c=8; + for(i=0;i<5;i++) + { + for(j=1;j<=c;j++) + printf(" "); + for(j=0;j<(2*i+1);j++) + printf("* "); + c=c-2; + printf("\n"); + } + return 0; +} From f4287c558461135b66f46067685735f49a001438 Mon Sep 17 00:00:00 2001 From: TushaarG Date: Fri, 25 Oct 2019 18:21:06 +0530 Subject: [PATCH 4/5] Second --- C/Patrun.c | 15 --------------- C/calci.c | 29 ----------------------------- C/ootpatang.c | Bin 0 -> 528 bytes 3 files changed, 44 deletions(-) delete mode 100644 C/Patrun.c delete mode 100644 C/calci.c create mode 100644 C/ootpatang.c diff --git a/C/Patrun.c b/C/Patrun.c deleted file mode 100644 index 381e53f..0000000 --- a/C/Patrun.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -int main() -{ - int i,j,c=8; - for(i=0;i<5;i++) - { - for(j=1;j<=c;j++) - printf(" "); - for(j=0;j<(2*i+1);j++) - printf("* "); - c=c-2; - printf("\n"); - } - return 0; -} diff --git a/C/calci.c b/C/calci.c deleted file mode 100644 index 1fac38c..0000000 --- a/C/calci.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -int main() -{ - int a[5],i=0,s=0; - float avg=0.0; - printf("Enter five number\n"); - for(i=0;i<5;i++) - { - scanf("%d",&a[i]); - } - for(i=0;i<5;i++) - { - s=s+a[i]; - } - avg=s/5; - printf("\nThe numbers above average\n "); - for(i=0;i<5;i++) - { - if(a[i]>avg) - printf("%d\n",a[i]); - } - printf("\nThe numbers belove average\n"); - for(i=0;i<5;i++) - { - if(a[i] Date: Fri, 25 Oct 2019 20:05:46 +0530 Subject: [PATCH 5/5] Final One --- C++/.gitignore | 1 - C++/ttt.cpp | 146 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 C++/ttt.cpp diff --git a/C++/.gitignore b/C++/.gitignore index d6b7ef3..f935021 100644 --- a/C++/.gitignore +++ b/C++/.gitignore @@ -1,2 +1 @@ -* !.gitignore diff --git a/C++/ttt.cpp b/C++/ttt.cpp new file mode 100644 index 0000000..783f290 --- /dev/null +++ b/C++/ttt.cpp @@ -0,0 +1,146 @@ +#include +using namespace std; + +char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; + +int checkwin(); +void board(); + +int main() +{ + int player = 1,i,choice; + + char mark; + do + { + board(); + player=(player%2)?1:2; + + cout << "Player " << player << ", enter a number: "; + cin >> choice; + + mark=(player == 1) ? 'X' : 'O'; + + if (choice == 1 && square[1] == '1') + + square[1] = mark; + else if (choice == 2 && square[2] == '2') + + square[2] = mark; + else if (choice == 3 && square[3] == '3') + + square[3] = mark; + else if (choice == 4 && square[4] == '4') + + square[4] = mark; + else if (choice == 5 && square[5] == '5') + + square[5] = mark; + else if (choice == 6 && square[6] == '6') + + square[6] = mark; + else if (choice == 7 && square[7] == '7') + + square[7] = mark; + else if (choice == 8 && square[8] == '8') + + square[8] = mark; + else if (choice == 9 && square[9] == '9') + + square[9] = mark; + else + { + cout<<"Invalid move "; + + player--; + cin.ignore(); + cin.get(); + } + i=checkwin(); + + player++; + }while(i==-1); + board(); + if(i==1) + + cout<<"==>\aPlayer "<<--player<<" win "; + else + cout<<"==>\aGame draw"; + + cin.ignore(); + cin.get(); + return 0; +} + +/********************************************* + FUNCTION TO RETURN GAME STATUS + 1 FOR GAME IS OVER WITH RESULT + -1 FOR GAME IS IN PROGRESS + O GAME IS OVER AND NO RESULT +**********************************************/ + +int checkwin() +{ + if (square[1] == square[2] && square[2] == square[3]) + + return 1; + else if (square[4] == square[5] && square[5] == square[6]) + + return 1; + else if (square[7] == square[8] && square[8] == square[9]) + + return 1; + else if (square[1] == square[4] && square[4] == square[7]) + + return 1; + else if (square[2] == square[5] && square[5] == square[8]) + + return 1; + else if (square[3] == square[6] && square[6] == square[9]) + + return 1; + else if (square[1] == square[5] && square[5] == square[9]) + + return 1; + else if (square[3] == square[5] && square[5] == square[7]) + + return 1; + else if (square[1] != '1' && square[2] != '2' && square[3] != '3' + && square[4] != '4' && square[5] != '5' && square[6] != '6' + && square[7] != '7' && square[8] != '8' && square[9] != '9') + + return 0; + else + return -1; +} + + +/******************************************************************* + FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK +********************************************************************/ + + +void board() +{ + system("cls"); + cout << "\n\n\tTic Tac Toe\n\n"; + + cout << "Player 1 (X) - Player 2 (O)" << endl << endl; + cout << endl; + + cout << " | | " << endl; + cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl; + + cout << "_____|_____|_____" << endl; + cout << " | | " << endl; + + cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl; + + cout << "_____|_____|_____" << endl; + cout << " | | " << endl; + + cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl; + + cout << " | | " << endl << endl; +} +