Homebasic c Understanding \n and tricks of for loop by drawing pattern!! byNEED WORK PRODUCE WORK -January 10, 2022 1 TASK-Write a C program to Generate following pattern:\n is used to shift to new line : see the code:Crack for pattern:1st and last line has full stars it mean a condition is required for 1st and last line.Other than 1st and last line each line has two stars and some space between them. CODE:#include<stdio.h> //star patternint main(){int i,j,n=5; //Here n is taken 5 you may increase or take from user: n is number of rowsfor (i=0;i<5;i++) //5 rows so 5 Iteration { if (i==0 || i==4) // Because at start and end we find a full line of * { for (j=0;j<9;j++) //Here the stars of up and down line are 9 you may change printf("*"); } else { printf("*"); for (j=1;j<8;j++) printf(" "); // Creating space between two stars printf("*"); } printf("\n");}getchar();return 0;}Expected Output: Tags: basic c pattern pyramid square Understanding \n and tricks of for loop by drawing pattern!! Facebook Twitter
Nice information thanx for sharing
ReplyDelete