Skip to main content

Posts

Showing posts with the label C Program

Snakes and Ladders game using C programming

Snakes and Ladders game using C programming: Program: #include <stdio.h> #include <stdlib.h> #include <time.h> #define BOARD_SIZE 100 #define NUM_SNAKES 5 #define NUM_LADDERS 5 // Function to roll a dice int rollDice() {     return rand() % 6 + 1; } // Function to generate random snakes and ladders void generateSnakesAndLadders(int snakes[], int ladders[]) {     int i;     for (i = 0; i < NUM_SNAKES; i++) {         snakes[i] = rand() % (BOARD_SIZE - 1) + 1;     }     for (i = 0; i < NUM_LADDERS; i++) {         ladders[i] = rand() % (BOARD_SIZE - 1) + 1;     } } // Function to check if a position is a snake head or ladder bottom int isSnakeOrLadder(int position, int snakes[], int ladders[]) {     int i;     for (i = 0; i < NUM_SNAKES; i++) {         if (snakes[i] == position) {             retu...

Hangman game using C programming

  Hangman game using C programming: Program: #include <stdio.h> #include <string.h> #include <ctype.h> #define MAX_WRONG_GUESSES 6 #define MAX_WORD_LENGTH 20 int main() { char word[MAX_WORD_LENGTH]; char guessed[MAX_WORD_LENGTH]; int numWrongGuesses = 0; int numCorrectGuesses = 0; int length; int i; char playAgain; do { printf("Enter the word to guess (up to %d characters): ", MAX_WORD_LENGTH - 1); scanf("%s", word); length = strlen(word); // Initialize guessed array with underscores for (i = 0; i < length; i++) { guessed[i] = '_'; } guessed[length] = '\0'; while (numWrongGuesses < MAX_WRONG_GUESSES && numCorrectGuesses < length) { printf("\nWord: %s\n", guessed); printf("Enter a letter: "); char guess; scanf(" %c", &guess);...