diff --git a/Chapter 5 - Practice Set/07_problem7.c b/Chapter 5 - Practice Set/07_problem7.c index 232915d..f6442f5 100644 --- a/Chapter 5 - Practice Set/07_problem7.c +++ b/Chapter 5 - Practice Set/07_problem7.c @@ -1,23 +1,29 @@ +// Write a program using function to print the following pattern (first n lines) #include -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; -} \ No newline at end of file +}