Write a C program that prints the following patterns separately, one below the other. Use nested For-loop to generate the patterns.
1
1*3
1*3*5
1*3*5*7
1*3*5*7*9
1*3*5*7
1*3*5
1*3
1
Answers
Answered by
2
Solution.
This is my approach for solving the question.
#include <stdio.h>
#include <stdlib.h>
int main() {
int n=9,i,j;
for(i=1-n;i<=n-1;i+=2){
for(j=1;j<=n-abs(i);j++){
if(j%2==1)
printf("%d",j);
else
printf("*");
}
printf("\n");
}
return 0;
}
Output.
1
1*3
1*3*5
1*3*5*7
1*3*5*7*9
1*3*5*7
1*3*5
1*3
1
See the attachment for verification.
Attachments:
Similar questions
History,
13 days ago
Math,
13 days ago
Physics,
26 days ago
Computer Science,
26 days ago
English,
8 months ago
Accountancy,
8 months ago
Geography,
8 months ago