I wrote these problems last night (except 19th problem), and code them at the morning, so, hope you all enjoy coding. This is ordiginal post of these 20 problems. Any question about the clarity of problems please post on below or contact me via pm, and your solutions too.

If you are beginner and you can solve these 20 problems by yourself, you are really a genius programmer with a very bright future ahead.

Although these problems (except 19th problem) I wrote last night but some of them might still familiar with you, some are ordiginal, some are mix-up or remake of classic/legacy problems.
`--------------------------------------`
To train your C skill, there are some rules you should follow when solve these problems or before post the solutions:
- Solutions must write in C language.
- Use just standard input and output, except 20th problem.
- Use just standard C (Ex: not include conio.h), any standard is approved, include C89/C90, C99, C11.
Ex:
`int main(void) or int main(int argc,char *argv[]), not int main() or main() or void main()`
`when declare a function that take no parameter, you must put a 'void' in.`
`Ex: int print(void);`
- You can post your codes here or paste onto an online paste website (like Pastebin or GitHub, etc...) and then post the link include your explainations here.
`--------------------------------------`
1. Write a program that prints "I like C language" to the screen without using "printf" function.
`--------------------------------------`
2. Write a program that enter two numbers x and y (0 <= x, y <= 10), print all expression make by these two numbers with errors handle.
Ex:

``````Input 1:
3 7

Output 1:
3 + 7 = 10
3 - 7 = -4
3 * 7 = 21
3 / 7 = 0
3 % 7 = 3
3 & 7 = 3
3 | 7 = 7
3 ^ 7 = 4
~ 3 = -4
~ 7 = -8
3 >> 7 = 0
3 << 7 = 384

Input 2:
4 0

Output 2:
4 + 0 = 4
4 - 0 = 4
4 * 0 = 0
Error: Division by zero.
Error: Division by zero.
4 & 0 = 0
4 | 0 = 4
3 ^ 0 = 4
~ 4 = -5
~ 0 = -1
4 >> 0 = 4
4 << 0 = 4

Input 3:
11 2

Output 3:
Error: Out of range.
``````

`--------------------------------------`
3. Write a conversion program that convert pounds to kilograms, the program must not exit except when enter -1.
`--------------------------------------`
4. Write a program that take a list of string (the list not longer than 1000 members and length of members not longer than 80) except "end" and return another list of string but reversed.
Ex:

``````Input:
DaniWeb
Hello World
end

Output:
dlroW olleH
``````

`--------------------------------------`
5. Write a program that take a binary number x (0 <= x <= 1111111111) and return a decimal number.
`--------------------------------------`
6. Write a program that calculate the value of this expression y = 2sqrt(x)/(1+x!)+x^20 (^ is expoment, x is integer and 0 <= x <= 20).
`--------------------------------------`
7. Write a program that count the number of prime numbers in any range [a, b] (0 <= a <= b <= 2000000000).
Ex:

``````Input:
0 10

Output:
4
``````

`--------------------------------------`
8. Write a program that count each digits in any range [a, b] (0 <= a, b <= 2000000000).
Ex:

``````Input:
20 0

Output:
0: 3
1: 12
2: 3
3: 2
4: 2
5: 2
6: 2
7: 2
8: 2
9: 2
``````

`--------------------------------------`
9. Write a program that take a string, delete a random character of the string, sort the string from smallest character to largest character, print out the sorted string.
Ex:

``````Input:
C is the best.

Output:
.Ceehisstt
``````

`--------------------------------------`
10. Write a program that solve the cubic equation.
Ex:

``````Input 1:
1 2 -3 0

Output 1:
x1 = 1
x2 = -3
x3 = 0

Input 2:
1 2 3 0

Output 2:
x1 = -1 + 1.4142i
x2 = -1 - 1.4142i
x3 = 0
``````

`--------------------------------------`
11. Write a program that find the largest and the second smallest number (in a list of integer numbers include n members) and their rate (0 < n <= 2000000000 and -2000000000 <= x[i] <= 2000000000). Make sure your program use only one loop.
Ex:

``````Input:
5
1 -2 3 3 1

Output:
3 2
1 2
``````

`--------------------------------------`
12. Write a program that take m, n and print out a sprial matrix size mxn (this case 'x' mean multiply) (0 < m, n <= 20).
Ex:

``````Input:
4 4

Output:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
``````

`--------------------------------------`
13. Write a program that take to matrix of same size nxn (0 < n <= 20), print out 2 invertible matrixes, sum of two given matrix, product of two given matrix.
Ex:

``````Input:
3
1 2 3
4 5 6
7 8 9
1 1 0
0 1 1
2 2 2

Output:
1 4 7
2 5 8
3 6 9

1 0 2
1 1 2
0 1 2

2 3 3
4 6 7
9 10 11

7 9 8
16 21 17
25 33 26
``````

`--------------------------------------`
14. Write a program that find a largest subsequence of a integer sequence of n members (0 < n < 1000 and -1000 < x[i] < 1000), the found subsequence must have smallest difference (Ex1: -4 and -2 so -4 is smallest difference, Ex2: 5 - 3 - 2 = 0 so 0 is called difference).
Ex:

``````Input:
5
1 2 0 4 -3

Output:
4
1 2 0 4
``````

`--------------------------------------`
15. Write program to find sercurity risks. Give 4 character ('a'..'z') matrixes of same size nxn (represent of 4 servers), find positions where all 4 matrixes have the same member (represent sercurity risk).
Ex:

``````Input:
2

1 1
3 4

1 1
5 4

1 1
3 4

1 1
-2 4

Output:
1: (0, 0) (0, 1)
4: (1, 1)
``````

`--------------------------------------`
16. Now is 1:39 PM (GMT+7). Exactly 5 billions year from now, the Sun will eat the Earth. Write a program to find out how many nanoseconds from now til the day the Earth is eaten by the Sun. Do not pre-calculate and just print out the result, and do not use any kind of floating point number.
`--------------------------------------`
17. Write a program that take the number of disks (0 < n <= 100), count and print out the least steps needed to solve the "Towers of Hanoi" problem.
Detail about "Towers of Hanoi" problem: There will be 3 pillars (towers). You will be given a number of discs (frequently just few discs) put in the first pillar follow the order (The largest disc at bottom and the smallest disc on the top). Your task is move all the disc go to another pillars without messing the order (You cannot put the smaller disc bellow the larger one at each step). Ex:

``````Input:
5

Output:
31
``````

`--------------------------------------`
18. Write a "Tic Tac Toe" game (play on console, each step enter a pair of integer number represent for coordinates of the game table 0..2 rows and 0..2 columns), a Player vs a Computer. Computer always go first, and your task is make the Computer smart enough to never be defeated.
`--------------------------------------`
19. "Next level" Minesweeper (This problem was writen by Le Minh Hoang (who wrote FFJS program))
Give a mine field size mxn (1 <= m, n <= 200). Filled in by numbers (each number 0 <= x <= 8) represent for the number of mines around that cell (each cell have maximum 8 cells around it), each cell contain at most 1 mine. Write a program that determine exactly which cell has mine. 0 represent for "has mine" and 1 represent for "has not mine".
Ex:

``````Input:
4 4
1 3 3 1
2 3 4 4
3 6 5 3
1 3 3 3

Output:
1 0 0 1
0 1 1 0
0 0 1 1
1 1 1 0
``````

`--------------------------------------`
20. Write a "next level" calculator, that can take an "infix expression" or a "postfix expression" ("Reverse Polish notation") at command line arguments, print out "postfix expression" or "infix expression" of given expression and its result.

``````The program must support:
- Signed floating point number.
- Maths operators:
+++ '+', '-', 'x', '/',
+++ 'd' (intergral divide, ex: 5 d 2 = 2),
+++ 'm' (modulus, ex: 5 m 2 = 1),
+++ '^' (expoment, ex: 2 ^ 3 = 8),
+++ '_' (radical, ex: 8 _ 3 = 2),
+++ 'L' (logarithm, ex: 8 L 2 = 3),
+++ 'l' (Neper logarithm, ex: 8 l = 2.07944 (5 digits accuracy)),
+++ '!' (factorial, ex: 5 ! = 120),
+++ 'C' (combination, ex: 4 C 2 = 6),
+++ 'A' or 'P' (permutation, some countries take letter A, somes take P, ex: 4 A 2 = 12)
+++ "sin(" ')', "cos(" ')', "tan(" ')', "cot(" ')',
+++ "asin(" ')', "acos(" ')', "atan(" ')', "acot(" ')'.
- Apsolute: '|', '|'.
- Parathenes: '(', ')'.
- Math error handle (overflow, division by zero).
- Syntax error handle.
- Each token separated by one space.
- If you going to enter a "infix expression", put "i:" at begin, else, put "p:" at begin.
- The "r:" in output mean "result".

Ex:
Input 1:
i: 3 + 4 - 5 m 2

Output 1:
p: 3 4 + 5 2 m -
r: 6

Input 2:
p: 3 6 + l 2

Output 2:
Error: Syntax error.

Input 3:
i: 2 ^ sin( ( 8 / 3 ) l )

Output 3:
p: 2 8 3 / l sin ^
r: 1.01194
``````

`--------------------------------------`

``````#include<stdio.h>
#include<time.h>
// ...

int main(void) {
time_t begin,end;
double runtime;

begin=clock() // <-- Start the timer

// ... <-- Put all things you need to calculate runtime in here

end=clock() // <-- Stop the timer

runtime=(double)(end-begin)/CLOCKS_PER_SEC; // <-- Calculate run time

printf("%lf s\n",runtime); // <-- Show the runtime of your program
// The runtime is accurate to nanosecond

// If using "scanf" or "scanf_s" before then you should put these line
int c;
while((c=getchar())!=10); // <-- clean the buffer

getchar(); // <-- Pause the screen til get hit
return 0;
}
``````

`--------------------------------------`
I have worked hours to making these problems as decent-good as possible, so, first, I hope you enjoy solving the problems, then, if you want to copy all of these problem to another place, please make a link to this post. Thanks you.

My name: Tien

For the first question can i use putchar(). Can you please tell what all allowed?

commented: I made a mistake and I can't edit the post. In the runtime tutorial section, I mean "microsecond", not "nanosecond". Thanks you for give me place. +0

Yes. For the first question, you can use anything except "printf".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.