diff --git a/.char_frequency.c.swp b/.char_frequency.c.swp new file mode 100644 index 0000000..fad59e7 Binary files /dev/null and b/.char_frequency.c.swp differ diff --git a/array b/array new file mode 100755 index 0000000..f3c11af Binary files /dev/null and b/array differ diff --git a/assignment4.txt b/assignment4.txt new file mode 100644 index 0000000..bff8ea4 --- /dev/null +++ b/assignment4.txt @@ -0,0 +1,10 @@ +Ava N. +July 5, 2016 + +1. Character arrays are arrays of characters. For example: char c='a';. Strings are arrays of characters. For example: char[10]="Hello World";. What this will do is assign char[0]='H', char[1]='e', char[2]='l', char[3]='l', char[4]='o', char[5]=' ', char[6]='W', char[7]='o', char[8]='r', char[9]='l', char[10]='d'. String assignment is only at declaration. Also, at the beginning of the program should use "#include ". + +2. The advantages of arrays in C are that it is very easy to store many integers in an array. The disadvantages of arrays in C are that the size can't change after the declaration. + +3. The compiler does not implicitly generate the address of the first element of an array when an array appears as an expression. + +4. Two strings can be compared to see if they're equivalent in content by using strcmp(), and if the output is 0, then the strings are equal. diff --git a/char_frequency.c b/char_frequency.c new file mode 100644 index 0000000..72e9542 --- /dev/null +++ b/char_frequency.c @@ -0,0 +1,46 @@ +/*Ava N.*/ +/*Write a program that takes a string of characters and returns the frequency of each character in that string.*/ +#include +#include + +int main(){ + char input_string[98]; /*input string*/ + char alpha_string[51]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int str_counter; + int alpha_counter; + int input_char; + int duplicate_count[51] = {0}; + + printf("Enter a character string less than 100 characters:"); + + scanf("%s",input_string); + +/* printf("Your input string is: %s \n", input_string); + printf("input string 0 is: %c\n", input_string[0]); + printf("input_string 1 is: %c\n", input_string[1]); + +*/ + + for (str_counter = 0; input_string[str_counter] != '\0'; str_counter++) + { + + for (alpha_counter = 0; alpha_counter < 52; alpha_counter++) + + { + + if (input_string[str_counter] == alpha_string[alpha_counter]) + duplicate_count[alpha_counter]++; + } + } + +/* printf("Letter a in duplicate counter array %d\n\n",duplicate_count[0]); */ + + + for (alpha_counter = 0; alpha_counter < 52; alpha_counter++) + + { + if (duplicate_count[alpha_counter] >= 1) + printf("%c was found %d times.\n",alpha_string[alpha_counter],duplicate_count[alpha_counter]); + } + return 0; +} diff --git a/frequency b/frequency new file mode 100755 index 0000000..a5d1574 Binary files /dev/null and b/frequency differ diff --git a/hangman b/hangman new file mode 100755 index 0000000..5a8ef8c Binary files /dev/null and b/hangman differ diff --git a/hangman.c b/hangman.c new file mode 100644 index 0000000..5a2c24b --- /dev/null +++ b/hangman.c @@ -0,0 +1,55 @@ +/*Ava N.*/ +/*a program implementing the Hangman game.*/ +/*I am submitting but would like to still work on this*/ +#include +int main(){ + + char word[4]="sand"; + char correct[4]="----"; + char input_guess; + int guessed_letters=0; + int correct_guesses; + char guesses [8]; + /*incorrect_correct_guesses[0]='\0';*/ + int counter; + char loop='y'; + while(loop == 'y') { + printf("Guess a letter: %c \n", input_guess); + scanf("%c", &input_guess); + for(counter=0; counter<4; counter++){ + if(input_guess==word[counter]){ + guessed_letters++; + //guesses--; + printf("You guessed a correct letter. \n"); + printf("These are the number of blank spots you have: %s \n", correct); + scanf("%s", &correct[4]); + printf("You used %d guesses of 8 guesses.\n", guessed_letters); + } + //} + else/*(input_guess!=word[counter])*/{ + guessed_letters++; + printf("You guessed an incorrect letter. \n"); + //guesses--; + printf("These are the number of blank spots you have: %s \n", correct); + scanf("%s", &correct[4]); + printf("You used %d guesses of 8 guesses.\n", guessed_letters); + //break; + } + } + printf("This is the word you have come up with so far: %s \n", correct); + //printf("You used %d guesses of 8 guesses. \n", guessed_letters); + if (guesses >= 8); { + printf ("You have lost. Try again next time.\n"); + break; + if(word==0 /*&& blank_spots==0*/); { + printf ("You got the word, sand! You have won the game!\n"); + //break; + } + printf("do you want to play again? (y/n) "); + scanf(" %c", &loop); + if(loop != 'y') + loop='n'; + } +} + return 0; +} diff --git a/integer_input_array.c b/integer_input_array.c new file mode 100644 index 0000000..50ebb3c --- /dev/null +++ b/integer_input_array.c @@ -0,0 +1,35 @@ +/*Ava N.*/ +/*Given an array of n integers where n > 1, return an array of same size an input array where at every index of the output array should contain the sum of all elements in the array except the element at the given index. You can have it so that the array is input by the user. */ +#include +#include +#include +#include + +int main() { + int array_size = 5; /* Array size of 5 */ + int input_array[array_size]; + int output_array[array_size]; + int array_sum = 0; + int counter; + + for(counter = 0; counter < array_size; counter++) + { + scanf("%d", &input_array[counter]); /* input numbers into array */ + } + + for(counter = 0; counter < array_size; counter++) + { + array_sum +=input_array[counter]; /* calculate sum of numbers in array */ + } + + printf("Sum of numbers in array is: %d\n", array_sum); + + for(counter=0; counter < array_size; counter++) + { + output_array[counter] = array_sum-input_array[counter]; + printf("output for element %d is %d\n", counter, output_array[counter]); + } + + +return 0; +} diff --git a/remdup b/remdup new file mode 100755 index 0000000..dfbe422 Binary files /dev/null and b/remdup differ diff --git a/remove_duplicates.c b/remove_duplicates.c new file mode 100644 index 0000000..e76b19b --- /dev/null +++ b/remove_duplicates.c @@ -0,0 +1,51 @@ +/*Ava N.*/ +/*Write a program that takes an array as input, removes duplicates, and outputs that array. */ +//I am submitting but would like to still work on this +#include +#include +#include +#include + +int main() { + int array_size = 5; /* Array size of 5 */ + int input_array[5]; + int output_array[5]; + int counter; + int check=0; + int duplicates=0; + int source=0; + + printf("\nInsert %d numbers into the array: \n", array_size); + + for(counter=0; counter<5; counter++) + { + scanf("%d", &input_array[counter]); /* input numbers into array */ + + printf("\n Numbers in the array: %d \n", input_array[counter]); + break; + } + + for(source=0; source < array_size; source++) + { + for(check=source+1; check