C Programming Techniques and Algorithms, Quizzes of Computer Science

Examples of c programming exercises, including reading user input, calculating equations, rock-paper-scissors game, and factorial calculation. It also includes code snippets for counting digits in an integer and solving simple mathematical problems.

Typology: Quizzes

2020/2021

Available from 06/05/2024

omr-22
omr-22 ๐Ÿ‡ช๐Ÿ‡ฌ

12 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Write a C program to read variable x from the user then check x to calculate
the following equation y
y=
{
5x2+2x+1x โ‰ฅ 0
2x3+1otherwise
2. Write a C program that shows how won in a rock, scissors, and paper game.
ask the user to enter player 1 hand and player 2 hand. (hand can be P, S, or
R)
3. Write a C program by using while loop that finds the factorial value of any
given natural number entered from the user
n !=n
(
nโˆ’1
) (
nโˆ’2
)
โˆ—โ€ฆโˆ—3โˆ—2โˆ—1
4. Using /= and ++ Counting the Digits in an Integer.
5. Answer the following questions
1. if m=3 and n=2 then w =??
a. w = ++ n + ++m
b. w = n -- + ++m
2. if z=3, y=5 and x=2 then k=??
a.
k=yโˆ’โˆ’+++ z/2โˆ—โˆ’โˆ’x
b.
k=โˆ’โˆ’zโˆ’โˆ’โˆ’x/4+yโˆ’โˆ’ยฟ5
1

Partial preview of the text

Download C Programming Techniques and Algorithms and more Quizzes Computer Science in PDF only on Docsity!

1. Write a C program to read variable x from the user then check x to calculate

the following equation y

y =

5 x 2

  • 2 x + 1 x โ‰ฅ 0 2 x 3
  • 1 otherwise

2. Write a C program that shows how won in a rock, scissors, and paper game.

ask the user to enter player 1 hand and player 2 hand. (hand can be P, S, or

R)

3. Write a C program by using while loop that finds the factorial value of any

given natural number entered from the user n^! = n^ (^ n โˆ’^1 )^ (^ n โˆ’^2 )โˆ— โ€ฆ โˆ—^3 โˆ—^2 โˆ—^1

4. Using /= and ++ Counting the Digits in an Integer.

5. Answer the following questions

1. if m=3 and n=2 then w =??

a. w = ++ n + ++m

b. w = n -- + ++m

2. if z=3, y=5 and x=2 then k=??

a. k^ =^ y โˆ’โˆ’+++^ z^ /^2 โˆ—โˆ’โˆ’ x

b. k^ =โˆ’โˆ’ z โˆ’โˆ’โˆ’ x^ /^4 +^ y^ โˆ’โˆ’ยฟ^5