Computer Science, asked by anooshahussain122, 26 days ago

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 anindyaadhikari13
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