├── Week 4 └── No assignments in week 4.txt ├── Week 6 └── Final Exam.txt ├── Week 1 ├── 1.Fix Dr. P’s mistake (week 1).txt └── 2. Print a poem.txt ├── README.md ├── Week 2 ├── 2. Int Quiz .txt ├── 1. Fix Dr. P’s mistake (week 2).txt └── 3. Expressions quiz.txt ├── Week 3 ├── 4. Peer graded Assignment Fix Dr P's mistake (week 3).txt ├── 5. Cond-comma-ops quiz.txt ├── 2. While loop questions.txt ├── 3. Switch Questions.txt ├── 6. Peer-graded Assignment Write a function that prints a table of values for sine and cosine between (0, 1).txt └── 1. Logic operators quiz .txt └── Week 5 └── Peer Graded.txt /Week 4/No assignments in week 4.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Week 6/Final Exam.txt: -------------------------------------------------------------------------------- 1 | DO ON YOUR OWN TO CLARIFY YOUR CONCEPTS -------------------------------------------------------------------------------- /Week 1/1.Fix Dr. P’s mistake (week 1).txt: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | printf(" hello world\n"); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C-for-Everyone-Programming-Fundamentals-by-University-of-California-Santa-Cruz 2 | No Assignments in Week 4 3 | -------------------------------------------------------------------------------- /Week 2/2. Int Quiz .txt: -------------------------------------------------------------------------------- 1 | 1) What does this program print, because of int kilometers? 2 | Ans : A marathon is 42 kilometer 3 | 2) Why did we change the format from lf to d? 4 | Ans : lf is a double and int answer would print incorrectly. -------------------------------------------------------------------------------- /Week 2/1. Fix Dr. P’s mistake (week 2).txt: -------------------------------------------------------------------------------- 1 | #include 2 | #define PI 3.14159 3 | int main(void) 4 | { 5 | int radius; 6 | printf("Enter radius:"); 7 | scanf("%d", &radius); 8 | printf("volume is : %lf \n\n", (4.00/3)*PI*(radius*radius*radius) ); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /Week 3/4. Peer graded Assignment Fix Dr P's mistake (week 3).txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include /* has sin(), abs(), and fabs() */ 3 | int main(void) 4 | { 5 | double interval; 6 | int i; 7 | for(i = 0; i <30; i++) 8 | { 9 | interval = i/10.0; 10 | printf("sin( %f ) = %f \t \n", interval,fabs(sin(interval))); 11 | } 12 | 13 | 14 | printf("\n+++++++\n"); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Week 3/5. Cond-comma-ops quiz.txt: -------------------------------------------------------------------------------- 1 | 2 | Q 1) Assume i = 1; j = 2; 3 | 4 | n = (i < j); 5 | 6 | Ans : n is 1 7 | 8 | Q 2) Assume i = 1; j = 2; 9 | 10 | n = (i == j)? 4:(i < j)?3:5; 11 | 12 | Ans: n is 3 13 | 14 | Q 3) Assume i = 1; j = 2; 15 | 16 | n = (i, j); 17 | 18 | Ans: n is 2 19 | 20 | Q 4) Assume i = 1; j = 2; 21 | 22 | n = i, j+1; 23 | 24 | Ans: n is 1 25 | 26 | Q 5) Assume i = 1; j = 2; 27 | 28 | n = (i < j)? 4: 6; 29 | 30 | Ans: n is 4 31 | 32 | -------------------------------------------------------------------------------- /Week 3/2. While loop questions.txt: -------------------------------------------------------------------------------- 1 | while (i < 5) 2 | i = i – 1; 3 | printf(“ i = %d“, i); 4 | 5 | Q 1) If i starts off as 2 (assume int i = 2 declared at the beginning of the code) then... 6 | Ans) printf will print continuously 7 | 8 | Q 2) If i starts off as 2 (assume int i = 2 declared at the beginning of the code) and the loop statement was i = i +1; printf will print ... 9 | Ans) i = 3 i = 4 i = 5 10 | 11 | Q 3) If i starts off as 15 (assume int i = 15 declared at the beginning of the code), printf will print ... 12 | Ans) will not print 13 | -------------------------------------------------------------------------------- /Week 3/3. Switch Questions.txt: -------------------------------------------------------------------------------- 1 | switch(i){ 2 | 3 | case 1: printf(“case 1 \n”); break; 4 | 5 | case 2: printf(“case 2 \n”); 6 | 7 | case 3: printf(“case 3 \n”);break; 8 | 9 | default: printf(“default case \n”); 10 | 11 | }; 12 | 13 | Use the code above for all of the questions. 14 | 15 | Q 1) If i starts off as 1 then printf will print 16 | Ans) case 1 17 | 18 | Q 2) If i starts out as 15 the printf will print 19 | Ans) default case 20 | 21 | Q 3) If i starts out as 2 the printf will print 22 | Ans) case 2 case 3 -------------------------------------------------------------------------------- /Week 3/6. Peer-graded Assignment Write a function that prints a table of values for sine and cosine between (0, 1).txt: -------------------------------------------------------------------------------- 1 | /* Program to print table of 2 | sine and cosines between 0 and 1 */ 3 | 4 | //first include preprocessing files 5 | 6 | #include 7 | #include 8 | int main(void) 9 | { 10 | //declaration 11 | float interval,x,y; 12 | int i; 13 | 14 | //for loop 15 | for(i = 0; i <10; i++) 16 | { 17 | interval = i/10.0; 18 | x=(sin(interval)); 19 | y=(cos(interval)); 20 | printf("sine(%f)=%f\t cosine(%f)=%f\n",interval,x,interval,y); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Week 2/3. Expressions quiz.txt: -------------------------------------------------------------------------------- 1 | 1) Assume that int a = 3, b = 4, c = -2; 2 | 3 | What is the value of a + b? 4 | 5 | Ans: 7 6 | 7 | 2) Assume that int a = 3, b = 4, c = -2; 8 | 9 | What is the value of -a + b? 10 | Ans : 1 11 | 12 | 3) Assume that int a = 3, b = 4, c = -2; 13 | 14 | What is the value of ++a + c? 15 | 16 | Ans : 2 17 | 18 | 4) Assume that int a = 3, b = 4, c = -2; 19 | 20 | What is the value of a / b? 21 | 22 | Ans: 0 23 | 24 | 5) Assume that int a = 3, b = 4, c = -2; 25 | 26 | What is the value of b / a? 27 | 28 | Ans: 1 29 | 30 | 6) Assume that int a = 3, b = 4, c = -2; 31 | 32 | What is the value of ++a + b++? 33 | 34 | Ans : 8 -------------------------------------------------------------------------------- /Week 3/1. Logic operators quiz .txt: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | #include 5 | 6 | 7 | int main(void) 8 | { 9 | int a = 0, b = 1, c = 2; 10 | 11 | If (a < b) printf (“ TRUE\n”); else printf(“ FALSE\n”); 12 | 13 | If (a < b - c) printf (“ TRUE\n”); else printf(“ FALSE\n”); 14 | 15 | If (b < c - 1) printf (“ TRUE\n”); else printf(“ FALSE\n”); 16 | 17 | If (!c) printf (“ TRUE\n”); else printf(“ FALSE\n”); 18 | return 0; 19 | } 20 | 21 | Q1) First line ? 22 | 23 | Ans : True 24 | 25 | Q2) Second line ? 26 | 27 | Ans : False 28 | 29 | Q3) Third line ? 30 | 31 | Ans : False 32 | 33 | Q4) Fourth line ? 34 | 35 | Ans : False 36 | -------------------------------------------------------------------------------- /Week 1/2. Print a poem.txt: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | printf(" Two roads diverged in a yellow wood \nAnd sorry I could not travel both \nAnd be one traveler, long I stood \nAnd looked down one as far as I could \nit bent in the undergrowth \n \n \nThen took the other, as just as fair \nAnd having perhaps the better claim \nBecause it was grassy and wanted wear \n Though as for that the passing there \nHad worn them really about the same \n \n \nAnd both that morning equally lay \nIn leaves no step had trodden black \n Oh, I kept the first for another day! \nYet knowing how way leads on to way\nI doubted if I should ever come back \n \n I shall be telling this with a sigh \nSomewhere ages and ages hence:\nTwo roads diverged in a wood, and I— \n I took the one less traveled by \nAnd that has made all the difference \n \n\n "); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /Week 5/Peer Graded.txt: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | C Compiler 4 | 5 | Average weight of elephant seals 6 | 7 | 26 Jun 2020 8 | 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | double average(int row,int column,int mat[row][column]) 18 | 19 | { 20 | 21 | int a; 22 | 23 | int b; 24 | 25 | double sum=0.0; 26 | 27 | for(a=0;a