Professional Documents
Culture Documents
CS1010E
Group 31
Extra ,
Missing ()
Extra \n, scanf(%d\n, &n);
Input r, output s
Just a for loop
Level 3
Level 4, accumulation
of all additional
values
s = s + k;
printf("(%d)", s);
For loop
for (k = row+1; k <= n;
k++)
{
print((%d), k);
}
Level 5
printf(,%d", s);
scanf("%d", &n);
}
printf("%d %d\n", max2,
max);
if (n > max)
{
max2 = max;
max = n;
}
else
if (n > max2)
{
max2 = n;
}
Be aware of
Size of array
Important
Modular coding
Palindrome number
Big number addition
Moving average (similar to max2 ?)
Inputs
Outputs
Relationship between inputs and outputs
Codecrunch Question
1. Palindromic large number:
Check whether a large number (<= 40 digits) is the
same whether read from left to right or right to left.
12345678987654321 is palindromic
12344321 is palindromic
1231 is not palindromic.
Codecrunch Question
1. Palindromic large number:
Solve the problem using 3 functions:
void readNum(int [], int *);
Codecrunch Question
2. Add Two Large Number
Add two big number (each <= 40 digits)
Cannot store into integer/add directly Overflow
Solve by 3 functions:
void readNumber(int []);
void add(int [], int [], int []);
void printNum(int []);
Codecrunch Question
2. Add Two Large
Number
555+28=?
Read
1555
+
28
1583
Compute
Read in as
{1, 5, 5, 5, undef, undef}
Transform to
{0, 0, 0, , 0, 1, 5, 5, 5}
Similarly for 28, after
transformation
{0, 0, 0, , 0, 0, 0, 2, 8}
Add from right to left, with carry
{0, 0, 0, , 0, 1, 5, 8, 3}
Codecrunch Question
3. Moving Average
The n-moving average of 10 number sequence {4,9,7,5,-8,-3,0,8,-9,2}
Solve by 3 functions:
void computePrintSeq(int x[], int n);