Writing, Running, and Fixing Code in C

Original Course link: Writing, Running, and Fixing Code in C Assignment GitHub - mvirgo/c-programming: Code worked on for Duke’s Intro to Programming in C course UNIX basic cat // output file to terminal emacs // open file in editor Emacs (be attention for the command, use lowercase, not uppercase) close a terminal tab, ctrl + shift + w close the entire terminal including all tabs, ctrl + shift + q githttp://git-scm.com/book/en/v2/ ...

2023-11-21 · 2 min · Atom.X

Overflow

Week 3 How to calculate binary, decimal, hexadecimal 3 parts of fields compound a float number. the most significant bit (MSB) 最高有效位 exponent 指数 mantissa 尾数 IEEE floating point Standard unsigned integer 无符号整数 that can only hold zero and positive numbers. For an n-bit integer, the range of values it can represent is[ 0 , 2^n ]. signed integer, For an n-bit integer, the range of values it can represent is[ -2^(n-1) , 2^(n-1) - 1]. ...

2023-11-18 · 5 min · Atom.X

Reading code

Week 2 Quiz Execute the following code by hand: int anotherFunction(int a, int b) { int answer = 2; int x = 0; printf("In anotherFunction(%d,%d)\n",a,b); while (b > a) { printf("a is %d, b is %d\n", a, b); answer = answer + (b - a); b -= x; a += x / 2; x++; } return answer; } int someFunction(int x, int y) { int a = x + y; if (x < y) { for (int i = 0; i < x; i++) { printf("In the loop with i = %d, a = %d\n", i, a); a = a + x; } } else { y = anotherFunction(y,a+1); } return a * (y-10); } int main(void) { int x = 2; int b = someFunction(3,x); printf("b = %d\n", b); printf("x = %d\n", x); return 0; } Execute main main //setep 1, execute main box, jump to calculate functions in b box. // get result from step 3 in y box, print first 4 lines In anotherFunction(2,6) a is 2, b is 6 a is 2, b is 6 a is 2, b is 5 //step 5, come back to main box, input last step value b=15 //step 6, print last two lines. b=15; x=2; b = someFunction(3,2); ...

2023-11-15 · 2 min · Atom.X

Programming Fundamentals

Original Course link: Programming Fundamentals Week 2 lvalue, rvalue eg. int x = 3; lvalue is x, rvalue is 3 erroneous code for loop = syntactic sugar, it allows you to write more compact code for counting, a common programming idiom(behavior, custom). What does f(5) evaluate to? int f (int n) { int ans = 0; for (int i = 1; i < n; i++) { if (i < n/2) { ans -= i; } else { ans += i; } } return ans; } Hint: dividing integers results in an integer answer. eg. 9/4 = 2, 5/2=2 (四舍五入rounding 3 is wrong) ...

2023-11-12 · 6 min · Atom.X

CS50

CS50x 2023 (harvard.edu) Codespace cs50 User Manual of C C standard library cs50 北美计算机四大本科课程设置: 编程语言学 算法与数据结构 操作系统 计算机网络 数据库 分布式系统 Spoiler tag problem code snippet posted should be posted with spoiler tag pseudocode? description text of ideas <math.h>Functions Set $m/n = (z/q)^x$, m≥n≥2, z>q≥2, x≥0, all arguments are positive integers. how to write an arithmetic function to get x value properly in c programming? could it be like below? ...

2023-11-1 · 1 min · Atom.X