Loops (pattern 6) ID-3462

Pattern 6 (Id-3462)
Given the value of ‘n’, develop an algorithm and write a C program to print the following pattern. When the value of ‘n’ is 5, the pattern will look as follows:

  *

 * *

*   *

 * *

  *

Input Format

First line contains the value of ‘n’



Output Format
Print the pattern given in the question
sol:-
C-CODE: 
#include<stdio.h>
void main(){
    int n;
    scanf("%d",&n);
    int i,j,count=0;
    for(i=0;i<n;i++){
        if(i<n/2){for(j=i;j<n/2;j++){
            printf(" ");
            count+=1;}}
        else{for(j=n/2-i+2;j<n/2;j++){
            printf(" ");
            count+=1;}}
            printf("*");
            count+=1;
            for(j=count+1;j<n-1;j++){printf(" ");}
                if(i!=0&&i!=n-1){
                    printf("*");}
                    count=0;
                    printf("\n");}}

Post a Comment

0 Comments