please help me..!
how to print this output using for loop?
output:
Code:S S S S S S S S S S S S S S S S
please help me..!
how to print this output using for loop?
output:
Code:S S S S S S S S S S S S S S S S
Announcements - C Programming
You need to read your book / course notes, and at least make an effort at solving your homework.
You're not going to get far with just dumping your assignment.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i done this, but don't understand that how to get this output using for loop!Code:/* S S S S S S S S S S S S S S S S */ #include<stdio.h> main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { if((i==2&&j==2)||(i==2&&j==3)||(i==2&&j==4)||(i==3&&j==2)||(i==3&&j==3)||(i==3&&j==4)||(i==4&&j==2)||(i==4&&j==3)||(i==4&&j==4)) printf(" "); else printf("S "); } printf("\n"); } }
Instead of using large multi-logic expressions, try to break the problem down into it's few cases, according to the row and column that is being printed out at that time.
In pseudo code:
It's a good idea to use the nested for loops for all row and column printouts, or "walking" through any 2D array. First one handles the rows, and that leaves you to concentrate on the for loops for the columns.Code:for each row in the box { for each column in the row I'm printing { if the row == the first one || the row == the last one, print out the S (regardless of the column) if the row is > the first one and less than the last one { if column == the first or column == the last one print the S else print a space char ' '. } } }
BTW, when you post a figure that you want help with, be SURE it's EXACT. There's a difference between the square diagram in your program, and the first diagram you posted.
Rather inconsistent pseudo code, but I'm trying to bring in just a bit of syntax, as well.
Last edited by Adak; 07-10-2012 at 12:52 AM.