Showing posts with label C-Programs. Show all posts
Showing posts with label C-Programs. Show all posts

Wednesday, 4 November 2015

Jumbled Words


#include<stdio.h>
#include<string.h>
int main()
{
FILE *f=fopen("words.txt","r");
int i=0,len,temp,j;
char c;
char word[15];
char shuffil_word[15],guessword[15];
start:
printf("WELCOME TO JUMBLED WORDS");
  printf("Guess the correct word\n");
     
  for (i=0;!feof(f);i++)
       {
        if((c=getc(f))==' ')
        break;
        else
        shuffil_word[i]=word[i]=c;
  }
  len=i;

for(i = 0; i < len; i++)
    {
        j = (rand()%len);
        temp = shuffil_word[i];
        shuffil_word[i] = shuffil_word[j];
        shuffil_word[j] = temp;
    }
    printf("\n");
    for(i=0; i<len; i++)
    {
          printf("%c", shuffil_word[i]);
    }
printf("\n\n");
again:
printf("Enter your guess...\n");
gets(guessword);
int guesslen = strlen(guessword);

if(guesslen!=len)
{
printf("\nThe Length of Guessed word and Actual Word is Mismatched\nTry Again...\n\n");
goto again;
}
for(i=0;i<len;i++){
if(guessword[i]!=word[i]){
printf("\nYou lost.");
goto gameloop;
}
}
printf("\nCongratulations! You Won the Game...!!!\n\n");
gameloop:
printf("\nDo you want to play again? (y/n)\n\n");
if(getch()=='y'||getch()=='Y')
goto start;
else
return;
}



NOTE: you need to create a text document with name of words and put program and text document in same folder
you need to enter the words in text document and program takes words from that document and jumbles it.




by
Kalyan Kurasala


Tuesday, 3 November 2015

TIC TAC TOE

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

int main (void)
{
            int player = 0;
            int winner = 0;
            int choice = 0;
            int row = 0;
            int column = 0;
            int line = 0;
            int i;
            char k;
            jump: char board [3][3] = {
                                                                 {'1','2','3'},
                                                                 {'4','5','6'},
                                                                 {'7','8','9'}
                                                               };
            clrscr();
            for (i = 0; i<9 && winner==0; i++)
            {
                        printf("\n\n");
                        printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                        printf("---|---|---\n");
                        printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                        printf("---|---|---\n");
                        printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);

                        player = i%2 + 1;

                        do
                        {
                                    printf("\nPlayer %d, please enter the number of the square "
                                                "where you want to place your %c: ",
                                                player,(player==1)?'X':'O');
                                    scanf("%d", &choice);


                                    row = --choice/3;
                                    column = choice%3;
                        }while(choice<0 || choice>9 || board [row][column]>'9');

                        board[row][column] = (player == 1) ? 'X' : 'O';


                        if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
                           (board[0][2]==board[1][1] && board[0][2]==board[2][0]))
                           winner = player;
                        else
                                    for(line = 0; line <=2; line++)
                                                if((board[line][0]==board[line][1] && board[line][0]==board[line][2])||
                                                            (board[0][line]==board[1][line] && board[0][line]==board[2][line]))
                                                            winner = player;


            }
                        printf("\n\n");
                        printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
                        printf("---|---|---\n");
                        printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
                        printf("---|---|---\n");
                        printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
            if(winner==0)
                                    printf("The game is a draw\n");
                        else
                                    printf("Player %d has won\n", winner);
            printf("Do you want to play another game(Y/N)");
            scanf("%c",&k);
            if(k=='y'||k=='Y')
                 go to jump;
            clrscr();
            return 0;

}

Guess the Number

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int random;
int userguess;
int noofguess=0;
int k;
int i;

printf("\t\tThis is simple guessing game\n");
printf("\t\tI am thinking numberin between 1 and 100\n");
printf("\t\tYou have to guess correct number\n");
printf("\t\tHere are some hints for you\n");
printf("\t\tYour game starts now\n");
printf("\t\tHAPPY GUESSING\n");
random=rand()%100+1;
{

  int i;
   printf("->Factors are: \n");
  for(i=1;i<=random;i++)
  {
      if(random%i==0)
         printf("%d \n",i);
  }
{
int count=0,i;
for(i=1;i<random-i;i++)
{
if(random%i==0)
count++;
}
if(count==2)
printf("->It is Prime number\n");
else
printf("->It is Composite number\n");
}
{
if(random%2==0)
printf("->it is even number\n");
else
printf("->it is odd nnumber\n");
}
{
int temp,reverse=10;
temp=random;
while(temp!=0)
{
reverse=reverse*10;
reverse=reverse+temp%10;
temp=temp/10;
}
if(random==reverse)
printf("->It is palindrome\n");
else
printf("->It is not a palindrome\n");
}
do
{
printf("*enter number in between 1 to 100*\n");
scanf("%d",&userguess);
noofguess++;
if(userguess>random)
printf("%d is greater than what I am thinking\n",userguess);
if(userguess<random)
printf("%d is less than what I am thinking\n",userguess);
}
while(random!=userguess);
printf("congrats you have guessed the no.\n");
printf("total guesses = %d ",noofguess);

 

getch();
return 0;
}
}