Skip to content

Instantly share code, notes, and snippets.

@chinchang
Last active October 13, 2019 06:32
Show Gist options
  • Save chinchang/b5b9f24ecfbc4ac36f8126710542dbd9 to your computer and use it in GitHub Desktop.
Save chinchang/b5b9f24ecfbc4ac36f8126710542dbd9 to your computer and use it in GitHub Desktop.
C exercises

Program 1

  • Take a sentence as input from user
  • Calculate and show: sentence's length, number of vowels.

Program 2

  • Take a number n between 5-20 as input from user
  • Create an array of length n
  • Put random number (1-100) in each element of the array
  • Display the array's element by comma separated. Eg. 1,56,2,88,2
  • Show the sum of the all the elements of the array

Program 3

  • Take a number n between 5-20 as input from user
  • Create an array of length n
  • Put random number (-100 to 100) in each element of the array
  • Find the largest number in the array
  • Add that largest number to all the array elements

Program 4 - Mini 2d game

  • Make a game grid of 10x10 length.
  • Each tile of the grid should show as a .
  • Example, a 3x3 grid would show as:
...
...
...
  • Place the game character at (0,0) and it show as x. Eg:
x..
...
...
  • Now continously take input from user. If user pressed up arrow, move the x character up, if user presses left, move left and so on...
  • On each arrow press, clear the screen and reprint the game grid with current state.

Program 5 - Fixed length Stack

  • Make an array of integers. Length should be 10. This array's length is always 10.
  • Fill the array with random integers from 0-100.
  • Print the array on the screen like so: 3 | 4 | 8 | 54 | 99
  • Now continuously take input from user.
  • If user presses a number, insert the number to the right. And because the array length should always be 10, remove one number from the left.
  • After any input, clear the screen and reprint the array.

Program 6 - Fixed length Stack (Level 2)

  • This is to be done on top above program "Fixed Length Stack".
  • If during input loop, user presses right arrow, set the insert direction to "right". That means any subsequent numbers should be inserted from right.
  • If during input loop, user presses left arrow, set the insert direction to "left". That means any subsequent numbers should be inserted from left.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment