From c583f36798996b84dbacc7a98783ed3f2fc68d7f Mon Sep 17 00:00:00 2001 From: Sheqi Date: Tue, 5 Jul 2016 03:34:17 -0400 Subject: [PATCH 1/5] duplicate.c --- 2duplicate.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2duplicate.c diff --git a/2duplicate.c b/2duplicate.c new file mode 100644 index 0000000..314440a --- /dev/null +++ b/2duplicate.c @@ -0,0 +1,29 @@ +#include + +int main(){ + int n,x; + int i=0; + int j=1; + int iarray[n]; + printf("Please type in an array:\n"); + scanf("%d",&iarray[n]); + for(i=0;iiarray[j]){ + x=iarray[j]; + iarray[j]=iarray[i]; + iarray[i]=x; + } + continue; + }} + for(i<0;i0&&iarray[i-1]==iarray[i]){ + break;} + printf("%d ",iarray[i]); + } + return 0; +} + + + + From 58147094310877f31cab648bc024914a42432f9c Mon Sep 17 00:00:00 2001 From: Sheqi Date: Tue, 5 Jul 2016 03:35:17 -0400 Subject: [PATCH 2/5] Assignment4 --- Assignment 4 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Assignment 4 diff --git a/Assignment 4 b/Assignment 4 new file mode 100644 index 0000000..ae482fa --- /dev/null +++ b/Assignment 4 @@ -0,0 +1,26 @@ +Assignment 4 Sheqi Zhang + +1. Discuss the differences between strings and a character array. +Answer: +A string is an array of chars, and an array is a group of characters within the same type. An array is static, and we can't change its size after declarition, while we can change the strings after declaeition. There is always a "\0" at the end of a string, while an array doesn't have that. + +2. Explain the advantages and disadvantages of arrays in C. +Answer: +Advantage: We can use it to store and use a group of similar data. +Disadvantage: We can't change the property like the size of the array, which will make our programming not convenient. + +3. When does the compiler not implicitly generate the address of the first element of an array? +Answer: +There are three situations: +1. The array is a string literal initializer for a character array; +2. The array is a operend of sizeof operator; +3. The array is a operand of "&" operator. + +4. How would two strings be compared to see if they’re equivalent in content? +Answer: +Using the string function: strcmp(string1,string 2); +It is comparing string 2 to string 1. +If it returns 0, the two string are equivalent. + + + From 7d17289d1213f9e67ad8db309921b799bddaddf7 Mon Sep 17 00:00:00 2001 From: Sheqi Date: Tue, 5 Jul 2016 03:35:49 -0400 Subject: [PATCH 3/5] Hangman --- HangmanGame.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 HangmanGame.c diff --git a/HangmanGame.c b/HangmanGame.c new file mode 100644 index 0000000..713b57d --- /dev/null +++ b/HangmanGame.c @@ -0,0 +1,34 @@ +#include +#include +#include + + +int main(){ + srand(time(0)); + char r =rand(); + int length = rand(); + length<15; + printf("This word has \"%d\" characters", length); + char word[length]; + char guess[length]; + int x = 0; + char letter; + while(x<4){ + scanf("%c",&letter); + if(letter==word[x]){ + guess[x]==letter; + printf("Please guess the next letter!\n"); + } + else + { + printf("Try again!\n"); + } + ++x; + continue; + } + return 0; + } + + + + From c8019766880cbb466b2b41b0f3213aa9c88c3829 Mon Sep 17 00:00:00 2001 From: Sheqi Date: Tue, 5 Jul 2016 03:37:59 -0400 Subject: [PATCH 4/5] array.c --- array.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 array.c diff --git a/array.c b/array.c new file mode 100644 index 0000000..ba18eec --- /dev/null +++ b/array.c @@ -0,0 +1,29 @@ +#include +#include + +int main(){ + int n; + int i=0; + int sum=0; + int inumbers[n]; + int inew[n]; + + printf("Please enter a group of number:"); + scanf("%u ",&inumbers[n]); + + while(i Date: Tue, 5 Jul 2016 03:38:34 -0400 Subject: [PATCH 5/5] frequency.c --- frequency.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 frequency.c diff --git a/frequency.c b/frequency.c new file mode 100644 index 0000000..88b9413 --- /dev/null +++ b/frequency.c @@ -0,0 +1,28 @@ +#include + +int main(){ + int n; + int i=0; + int j=0; + char ia[n]; + char jletter[52]; + int jtimes[52]={0}; + n<=100; + printf("Please type in an array with only letters:\n"); + scanf("%c",&ia[n]); + for(i=0;i<52;i++){ + for(j=0;j<52;j++){ + if(ia[i]==jletter[j]) + ++jtimes[j]; + continue; + } + printf("\"%c\":\"%d\"\n",jletter[j],jtimes[j]); + continue; + } + return 0; +} + + + + +