Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions Chapter 5 - Practice Set/07_problem7.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
// Write a program using function to print the following pattern (first n lines)
#include <stdio.h>

int main(){
int n = 3;
for (int i = 0; i < n; i++)
void star(int);
void star(int a)
{

for (int i = 0; i < a; i++)
{
// This loop runs from 0 to 2
// if i = 0 ---> print 1 star
// if i = 1 ---> print 3 stars
// if i = 2 ---> print 5 stars
// no_of_stars = (2*i+1)

// This for loop prints (2*i+1) stars
for(int j=0; j<2*i+1;j++){
for (int j = 0; j < ((2 * i) + 1); j++)
{
printf("*");
}

// This printf prints a new line
printf("\n");
}

}
// The loop runs from 0 to 2
// if i = 0 ---> print 1 star
// if i = 1 ---> print 3 stars
// if i = 2 ---> print 5 stars
// no_of_stars = (2*i+1)

// This for loop prints (2*i+1) stars
int main()
{
star(20);
return 0;
}
}