Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions duplicateArray.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

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");


}
50 changes: 50 additions & 0 deletions hangman.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Yael Kelmer.
This code allows the player to play a game of hangman.*/

#include <stdio.h>
#include <string.h>

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;
}

}

}

38 changes: 38 additions & 0 deletions stringfreq.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <string.h>

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]);
}
}
}



49 changes: 49 additions & 0 deletions sumarray.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

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");

}