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
29 changes: 29 additions & 0 deletions 2duplicate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

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;i<n;i++){
for(j=i+1;j<=n;j++){
if(iarray[i]>iarray[j]){
x=iarray[j];
iarray[j]=iarray[i];
iarray[i]=x;
}
continue;
}}
for(i<0;i<n;i++){
if(i>0&&iarray[i-1]==iarray[i]){
break;}
printf("%d ",iarray[i]);
}
return 0;
}




26 changes: 26 additions & 0 deletions Assignment 4
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!


3. When does the compiler not implicitly generate the address of the first element of an array?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the short answer is that a compiler doesn't generate the address whenever it appears in an expression.

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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!

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.



34 changes: 34 additions & 0 deletions HangmanGame.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


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




29 changes: 29 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <string.h>

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<n){
sum += (int) inumbers[i];
// printf("sum=%d",sum);
i++;
// printf("i=%d",i);
continue;
}
//printf("sum=%d",sum);

inew[i]= sum - inumbers[i];
printf("%u",inew[n]);

return 0;
}


28 changes: 28 additions & 0 deletions frequency.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

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