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
Binary file added array
Binary file not shown.
39 changes: 39 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//Emma
//returning an arry with sum


#include <stdio.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job on doing this in a super efficient way! The only thing is I'd recommend having the user input the array, but that's not as important. Nice job!

#include <string.h>


int main(){

int array[8]={1, 2, 5, 7, 7, 8, 10, 4};

int out[8];

int i;
int sum =0;
for(i=0; i<8;i++){

sum = sum + array[i];

}

int j;
int print;
for(j=0; j<8;j++){

out[j] = sum - array[j];



}

for(print=0; print<8; print++){
printf("%d\n", out[print]);
}

return 0;

}
11 changes: 11 additions & 0 deletions assignment4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Emma Ladouceur

1. A character array in c separates each letter into its own section. s[10] = {"h", "e", etc..}
whereas if you wanted it as a string you could simply put it as s[10] = {"hello"}. The cmputer still sees each space as 0-10, but it will recognize each section.
C doesn't have its own thing for a string, so in a sense a string is just a character array
Copy link
Contributor

Choose a reason for hiding this comment

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

a string is basically a character array except it always includes a null terminator at the end ("\0").


2. Arrays in c are kind of confusing because you cannot mix different values. Its either char or int which makes it extremely hard to put things together. In ruby you can have numbers and strings and chars. Its also really really challenging, maybe impossible to create an empty array. Ispent about 4 hours this weekend trying to figure that out and even purchased a text book. If you want to set. The arrays are static and the size cannot change after initialization. I can think of no advantages.

3. When an array is in an an expression it won't generate the address the first element of the array.
Copy link
Contributor

Choose a reason for hiding this comment

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

right!


4. If theyre the exact same 0 will be returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

right, using strcmp!

Binary file added count
Binary file not shown.
118 changes: 118 additions & 0 deletions count.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//Emma Ladouceur
//counts the occurence of letters in a string
//I feel like I'm close in this one but it was printing before and now it won't. I tried debugging and it compiles, but it doesn't go further than that. I'll finish all of these things after class, but I think i need some ideas, so maybe we'll go over it. Otherwise I'll just work on it more tomorrow, but I've spent about 4 hours on these last two.
// I do know that it's not recognizing the increases when you type in strings or the switch statement because I added an a++ at the bottom and it prints a:100, but i don't know how to fix it.
#include <stdio.h>


int main(){

int a=0, b=0, c=0, d=0, e=0,f=0,g=0,h=0,i=0,j=0,k=0,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;

int print;

int ii;
int occur=100;
char string[occur];

printf("Enter a string of characters");
scanf("%c", &string[occur]);

for(ii=0; ii<occur; ii++)
{
switch(string[ii]){

case 'a':
a++;
break;

case 'b':
b++;
break;

case 'c':
c++;
break;

case 'd':
d++;
break;

case 'e':
e++;
break;

case 'f':
f++;
break;

case 'g':
g++;
break;

case 'h':
h++;
break;

case 'i':
i++;
break;

case 'j':
j++;
break;
}

a++;

}



if(a>0){
printf("a : %d\n", a);
}
if(b>0){
printf("b : %d\n", b);
}
if(c>0){
printf("c : %d\n", c);
}

if(d>0){
printf("c : %d\n", d);
}

if(e>0){

printf("e : %d\n", e);
}

if(f>0){
printf("f : %d\n", f);
}

if(g>0){
printf("g : %d\n",g);
}

if(h>0){
printf("h : %d\n", h);

}

if(i>0){
printf("i : %d\n", i);
}

if(j>0){
printf("j : %d\n", j);
}



return 0;

}


Binary file added double
Binary file not shown.
37 changes: 37 additions & 0 deletions double.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//Emma Ladouceur
//This does not work!
//I've tried so many things but cannot figure it out. I honestly don't know what else to try so if we could go over after class I would really appreciate it
//It compiles and prints 6 things, but ideally it would 1 only print 3 and 2 it would be the correct 3 things
//on the bright side, nothing is negative anymore and it does compile
#include <stdio.h>


int main(){
int number, i, k, h, j;
int arr1[6] = {1,1,2,2,3,3};
int arr2[6];

arr1[6] = arr2[6];
for(i=0; i<6; i++){
for(j=0;j<6;j++){
if(arr1[i]==arr1[j]){
break;
}

if(i==j){
arr1[i]=arr1[j];
i--;
}
}

}



for(k=0; k<6; k++){
printf("%d\n", arr2[k]);
}


return 0;
}
Binary file added hangman
Binary file not shown.
37 changes: 37 additions & 0 deletions hangman.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//Emma Ladouceur
//This is incomplete but in the works, I took so long on the other two that by the time I got to this I had very little time. SO sorry!

#include <stdio.h>

int main(){


int i, j,k;

printf("This is Hangman\n Enter a letter to guess.");

char string[3] = "NYC";

char guess;

scanf("%c", &guess);

printf("You have 4 guesses");

for(i=0; i<4; i++){
if(guess =='N' || guess=='Y' || guess=='C'){

printf("youre right.");

}

else{
break;
}

i++;
}



}