12. Function – 4 Sum
#include <stdio.h>
int sum(int a, int b);
int main() {
printf(“%d”, sum(sum(1, 2), sum(3, 4));
return 0;
}
int sum(int a, int b) {
return a+b;
}
15. undefined reference to '<FUNC>'
collect2: ld returned 1 exit status
Open ‘Build Configuration’
menu
16. undefined reference to '<FUNC>'
collect2: ld returned 1 exit status
Append –lm and apply
17. Practice 1
𝑁 = 𝑛 + 𝛼
𝑛 𝑖𝑠 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, 0 ≤ 𝛼 < 1
Input
Real number 𝑁 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
Output
𝑁 = 𝑛 + 𝛼 (𝑁, 𝛼 𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
*DO NOT UES if
Ex) Ex)
5.43 0
5.43=5+0.43 0.00=0+0.00
18. Practice 2
𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
Input
Real number 𝑎, 𝑏, 𝑐 (𝑎 ≠ 0, 𝑏2
− 4𝑎𝑐 > 0)
Output
Find the value of 𝑥 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
Ex) Ex)
1 5 3 4.8 15.9 3.2
-0.70 -4.30 -0.22 -3.10
19. Practice 3
a mod b = 𝑟0
b mod 𝑟0 = 𝑟1
𝑟0 mod 𝑟1 = 𝑟2
…
𝑟𝑛−1 mod 𝑟𝑛 = 0
𝑟𝑛 is the greatest common divisor (gcd) of a and b
For example,
1071 mod 462 = 147
462 mod 147 = 21
147 mod 21 = 0
21 is the greatest common divisor (gcd) of 1071 and 462