Qn: Write the C program logic to print as follows
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-By Mariyappan, Last Update On 28th May,2019 07:14 pm
இதை கீழ்க்கண்டவாறு இரண்டாக பிரித்து. அவற்றின் logic-களை ஒன்றாக இணைத்தால் நமக்கு தேவையான output கிடைத்துவிடும்.
part-1 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * part-2
இவற்றை ஒன்றாக இணைக்கும்போது part-1ல் உள்ள கடைசி row மற்றும் part-2ல் உள்ள முதல் row இவற்றில் எதாவது ஒன்றை மட்டும் தான் எடுத்துகொள்ளவேண்டும்.
//part-1 logic
for(int row=1;row<=n-1;row++){
for(int col=1;col<=row;col++){
Logic to print stars here..
}
for(int s=1;s<=(2*n-2*row)-1;s++){
Logic to print space here..
}
for(int col=1;col<=row;col++){
Same Logic to print stars here..
}
printf("\n");
}
for(int p=1;p<=(2*n)-1;p++){
Logic to print last row stars here..
}
printf("\n");
//part-2 logic
for(int row=n-1;row>=1;row--){
for(int col=1;col<=row;col++){
Logic to print stars here..
}
for(int s=1;s<=(2*n-2*row)-1;s++){
Logic to print space here..
}
for(int col=1;col<=row;col++){
Same Logic to print stars here..
}
printf("\n");
}
Complete Program
#include<stdio.h>
#include<conio.h>
int main(){
int n,row,col,s,p;
printf("Enter how many rows you want: ");
scanf("%d",&n);
//row should end with n-1 its important
for(row=1;row<=n-1;row++){
//print stars
for(col=1;col<=row;col++){
printf("*");
}
//print space
for(s=1;s<=(2*n-2*row)-1;s++){
printf(" ");
}
//print stars
for(col=1;col<=row;col++){
printf("*");
}
printf("\n");
}
//print last row stars
for(p=1;p<=(2*n)-1;p++){
printf("*");
}
printf("\n");
//row should start with n-1 end with 1. its important
for(row=n-1;row>=1;row--){
//print stars
for(col=1;col<=row;col++){
printf("*");
}
//print space
for(s=1;s<=(2*n-2*row)-1;s++){
printf(" ");
}
//print stars
for(col=1;col<=row;col++){
printf("*");
}
printf("\n");
}
return 0;
}
Output:
Enter how many rows you want: 5
Enter how many rows you want: 5
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Pgcomments
இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.
Comments