You are on page 1of 2

Tutorial 3

Generate the code in C for the following problems

1) Write a program that will print out 1 to 10 on screen using


a) while loop
b) do while loop
c) for loop

2) Write a program that will read a line of text in lowercase and convert it into uppercase
using

a) while loop
b) do while loop
c) for loop

3) Generate a program that will generate the outline of a diamond shape using the *
character, i.e. your program should output something like the following (using
imbedded loops)

**
* *
* *
* *
* *
* *
* *
**

4) Write a program that will generate the 1st N fibonacci numbers i.e., where N is inputted
by the user

1 1 2 3 5 8 13 etc…
5) Write a program that will generate the following pyramid of digits

1
232
34543
4567654
567898765

6) Write a program that will allow the computer to be used as an ordinary desk
calculator. Consider only addition, subtraction, multiplication and division

7) Write a program that will calculate sin(x) by using the series

Sin(x) = x – (x3)/3! + (x5)/5! – (x7)/7! + ……

Note that x is in radians

You might also like