Course C Initial 10th – Exercises with If-Else

Lesson 10.

As we see in the previous lesson, now we’ll make some algorithms to practice. Those are 10 questions. I recommend that you make this algorithms because it’ll help you in the future.

1- Make an algorithm that reserves how tall is a person and test this conditions:
  • If the Tall is greater than 1.90, printf (“You can play basketball”);
  • If the Tall is smaller than 1.50, printf (“You’re not taller”);
  • if the Tall is greater or equal to 1.50 and smaller or equal than 1.90, printf (“You’re between arrive”);
2- Make an algorithm that works as a game, it may ask to user “What’s the Spanish Capital?” so the user will have available 4 possibility, they’re respectively a) Madrid, b) Barcelona, c) Vigo, d) Sevilla, after will be tested them. Note: use for store the result, a character type variable.
  • If the variable is equal to ‘a’, so printf (“You’re Wright”);
  • Else, so printf (“You’re wrong”);
3- Make an algorithm that works as a table, so the user type a value and it is stored in a variable. The algorithm is for the user type the result of the sum 985+856 and it’ll be tested.
  • If the user typed 1841, so printf (“The answer is corret”);
  • Else, printf (“Don’t you know sum?”);
4- Make an algorithm that reserves 4 numbers, so test if they’re equal or what’s the larger between them.
5- Make an algorithm that reserves a number, an operator and other number, so calculates the operation solicited. For example: 7*2 is equal to 14, use an int, char and int respectively. Test what operation will be made and print the result.
6- Make an algorithm that reserves the product code and the quantity, so calculate the prices. Note: before defines how you can see below:
  • M’ – Milk – U$ 1,00 1L.
  • P’ – Potato – U$ 2,50 Kg.
  • E’ – Meat – U$ 10,00 Kg.
  • J’ – Juice – U$ 0,50 each.
Use if else to test the options. Note: use a special case for when the code was incorrect. After multiple the price by quantity and print the total price.
7- Make an algorithm that test if a number typed by use is negative, or null, or positive.
  • If Num==0, print “This Number is Null”
  • Else if Num<0, print “This Number is Negative”
  • Else if Num>0, print “This Number is Positive”
8- Make an algorithm that test if a number typed by user is pair or impair. Note: a number is pair only if it’s divisive by 2, else, it’s impair.
9- Make an algorithm that reserves 5 numbers in different variables, so use a variable called Cont to sum the quantity of numbers greater than 0, it may be initialized with 0. Just test if it is greater than 0, so print a message saying the quantity of positive numbers.
10- Make an algorithm that reserves 5 numbers in different variables, so use a variable called Cont to sum the quantity of numbers smaller than 0, it may be initialized with 0. Just test if it is smaller than 0, so print a message saying the quantity of negative numbers.
Well, that’s all folks! In the next lesson, we’ll see the Switch Command! See you later!

Comentários

More Famous Posts

Course Python For Life 4 – Variables

Course C Initial 14th – Do While