Starting from:

$25

IT1010 - Lab Sheet4  -   Introduction to Programming - Solved

Objectives:  

At the end of the class the students should be able to:  

 Implement simple functions in C language  

 

Exercise 1:  

 

a)      Write a function drawLines() to draw the below figure.  

 

*  * * * * * * * * *  

*  * * * * * * * * *  

*  * * * * * * * * *  

*  * * * * * * * * *  

*  * * * * * * * * *  

 

b)      Call the drawLines() function in your main program to draw the rectangle.  

 

c)      

 
 
 

Write another function called drawLinesWithRow() to pass the no of lines(rows) as a parameter.  

 

 

Ex: void drawLinesWithRow(int rows)  

If 3 is passed as the number of rows, the function should print,  

 

*  * * * * * * * * *  

*  * * * * * * * * *  

*  * * * * * * * * *  

 

d)      Call the function created in section c) in your main program and draw two rectangles with 6 and 12 rows.  

                                                                                                                       

  

e)      Write another function called drawLinesWithRowCol() to pass the no of rows and columns as parameters.  

Ex: void drawLinesWithRowCol (int rows, int cols);  

If 3 is passed as the number of rows and 5 as the number of columns, the function should print,  

 

*  * * * *  

*  * * * *  

*  * * * *  

 

f)       Call the function created in section e) in your main program and draw a rectangles with 7 rows and 4 columns.  

 

g)      Draw the following figure in your program using the functions you have created in previous sections.  

*  * * * *  

*  * * * *  

*  * * * *  

*  * * * *  

*  

 
 
 

* * * *  

 

h)      Write a new function to print a rectangle with a given width, height and the character as the parameter. The rectangle should be printed using that character. Call the function in your main program 

                                                                                                                                                           

More products