From 3b761cb04ff9c8419c714440e04bafea79e8d87e Mon Sep 17 00:00:00 2001 From: Md Asif <87461866+MdAsifInIT@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:59:58 +0530 Subject: [PATCH 1/2] Update 07_problem7.c --- Chapter 5 - Practice Set/07_problem7.c | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Chapter 5 - Practice Set/07_problem7.c b/Chapter 5 - Practice Set/07_problem7.c index 232915d..fa23f13 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"); } - +} +// 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 +int main() +{ + star(20); return 0; -} \ No newline at end of file +} From 9bff4578f4819e14a4987e914ef2af5748a2fec0 Mon Sep 17 00:00:00 2001 From: Md Asif <87461866+MdAsifInIT@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:01:29 +0530 Subject: [PATCH 2/2] Update 07_problem7.c --- Chapter 5 - Practice Set/07_problem7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter 5 - Practice Set/07_problem7.c b/Chapter 5 - Practice Set/07_problem7.c index fa23f13..f6442f5 100644 --- a/Chapter 5 - Practice Set/07_problem7.c +++ b/Chapter 5 - Practice Set/07_problem7.c @@ -15,7 +15,7 @@ void star(int a) printf("\n"); } } -// This loop runs from 0 to 2 + // 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