diff --git a/duplicateArray.c b/duplicateArray.c new file mode 100644 index 0000000..29ecdf0 --- /dev/null +++ b/duplicateArray.c @@ -0,0 +1,54 @@ +/* Yael Kelmer. + This code asks the user to input an array with duplicate integers. The code then removes the duplicates and prints the new array.*/ + +#include + +int main () +{ + printf ("Please insert the length of the array (how many integers you want in your list of integers)\n"); + int lengthArray; + scanf ("%d", &lengthArray); + printf ("Please insert the integers you want to be in the array (remember it has to match the length of the array). Insert duplicates of some integers and I will return an array without those duplicates. \n"); + + int userArray [lengthArray]; + + int i; + int userInput; + for (i= 0; i < lengthArray; i++) { + scanf ("%d", &userInput); + userArray [i] = userInput; + } + + + int newArray [lengthArray]; + int j; + int newLength = 0; + for (i = 0; i < lengthArray; i++) { + int check = 0; + for (j = 0; j < newLength; j++) { + if (userArray [i] == newArray [j]) { + check = 1; + break; + } + } + if (check == 0) { + newArray [newLength] = userArray [i]; + newLength++; + } + + } + + printf ("This is your original array: [ "); + for (i = 0; i < lengthArray; i++) { + printf ("%d ", userArray [i]); + } + printf ("]\n"); + + printf ("This is your new array: [ "); + for (i = 0; i < newLength; i++) { + printf ("%d ", newArray [i]); + } + printf ("]\n"); + + +} diff --git a/hangman.c b/hangman.c new file mode 100644 index 0000000..384ac82 --- /dev/null +++ b/hangman.c @@ -0,0 +1,50 @@ +/* Yael Kelmer. + This code allows the player to play a game of hangman.*/ + +#include +#include + +int main() +{ + char hangmanWord [7] = "peanut"; + + char userGuess; + int i; + char fillArray [7] = "______"; + char incorrectGuesses [8]; + incorrectGuesses[0] = '\0'; + int incorrectGuessIndex = 0; + + int check = 0; + + while (1) { + printf ("Please take your guess.\n"); + scanf (" %c", &userGuess); + check = 0; + for (i = 0; i < 6; i++) { + if (userGuess == hangmanWord [i]) { + fillArray [i] = userGuess; + check = 1; + } + } + if (check == 0) { + incorrectGuesses[incorrectGuessIndex] = userGuess; + incorrectGuessIndex++; + incorrectGuesses[incorrectGuessIndex] = '\0'; + } + + printf ("This is your hangman situation: %s\n", fillArray); + printf ("These are your incorrect guesses: %s\n", incorrectGuesses); + if (incorrectGuessIndex == 8) { + printf ("You lose!\n"); + break; + } + if (strcmp (hangmanWord, fillArray) == 0) { + printf ("You won!\n"); + break; + } + + } + +} + diff --git a/stringfreq.c b/stringfreq.c new file mode 100644 index 0000000..07d3e4c --- /dev/null +++ b/stringfreq.c @@ -0,0 +1,38 @@ +/* Yael Kelmer. + This code takes a user inputed string and counts the amount of times each letter shows up in the string. */ + +#include +#include + +int main () +{ + + printf ("Please type in the letters you want in your string\n"); + char userString [100]; + fgets (userString, sizeof(userString), stdin); + + int stringLength = strlen (userString); + userString [stringLength - 1] = '\0'; + stringLength -= 1; + + int ASCIIarray [128]; + + int i; + for (i = 0; i < 128; i++) { + ASCIIarray [i] = 0; + } + + for (i = 0; i < stringLength; i++) { + char letter = userString [i]; + ASCIIarray [(int) letter] += 1; + } + + for (i = 0; i < 128; i++) { + if (ASCIIarray [i] > 0) { + printf ("%c = %d\n", (char) i, ASCIIarray [i]); + } + } +} + + + diff --git a/sumarray.c b/sumarray.c new file mode 100644 index 0000000..15820cf --- /dev/null +++ b/sumarray.c @@ -0,0 +1,49 @@ +/*Yael Kelmer. + This code takes a user inputed array and outputs an array of the sum of all the integers in the array execpt for the indexed integer*/ + +#include + +int main () +{ + + printf ("Please insert the length of the array (how many integers you want in your list of integers)\n"); + int lengthArray; + scanf ("%d", &lengthArray); + printf ("Please insert the integers you want to be in the array (remember it has to match the length of the array) \n"); + + int userArray [lengthArray]; + + int i; + int userInput; + for (i = 0; i < lengthArray; i++) { + scanf ("%d", &userInput); + userArray [i] = userInput; + } + + + int outputArray [lengthArray]; + + int j; + int sum = 0; + for (j = 0; j < lengthArray; j++) { + sum = sum + userArray [j]; + } + + for (i = 0; i < lengthArray; i++) { + outputArray [i] = sum - userArray [i]; + + } + + printf ("This is your input array: [ "); + for (i = 0; i < lengthArray; i++) { + printf ("%d ", userArray [i]); + } + printf ("]\n"); + + printf ("This is your ouput array: [ "); + for (i = 0; i < lengthArray; i++) { + printf ("%d ", outputArray [i]); + } + printf ("]\n"); + +}