Friday, December 4, 2020

Problem Solving through programming In C Session-1 Problem - 2 Programming Question Solution

 

Session-1 Problem - 2

Due on 2020-12-04, 11:00 IST
Write a program which accepts number of rows and columns and prints a hollow rectangle using asterisk (*) symbol as given in the example. (Please note that the printing starts from the first row and first column, do not use any blank space between two asterisk (*), use \n for next row.

For row =6 and column = 20

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

*                          *

*                          *

*                          *

*                          *

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

Your last recorded submission was on 2020-12-04, 10:12 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
3
void print_rectangle(int n, int m); 
4
int main()  
5
{  
6
    int rows, columns;  
7
    scanf("%d", &rows); //No of rows is accepted from test data
8
    scanf("%d", &columns); //No of columns is accepted from test data
9
    print_rectangle(rows, columns);  
10
    return 0;  
11
}  
12
13
//Write the above function to complete the program
14
void print_rectangle(int n, int m) 
15
{ 
16
    int i, j; 
17
    for (i = 1; i <= n; i++) 
18
    { 
19
        for (j = 1; j <= m; j++) 
20
        { 
21
            if (i==1 || i==n || j==1 || j==m)             
22
                printf("*");             
23
            else
24
                printf(" ");             
25
        } 
26
        printf("\n"); 
27
    } 
28
  
29
}

No comments:

Post a Comment