English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

Lya,

Think about your problem like a n*n matrix which you have to iterate with two counters i and j. You just have to manipute them to satify the condition where you will print a '*'.
For eg, the first * will be printed when i (row counter) is 0 and j (column counter) is n/2.
You can build a solution using this funda.

#include
#include

int main(int argc, char *argv[]) {
int n = (argc > 1 ? atoi(argv[1]): 5);
int halfn = n/2;
int i, j;

for(i = 0; i <= halfn; i++) {
for(j = 0; j < n; j++) {
if( (j == halfn - i) || (j == halfn + i ) ) {
printf("*");
}
else {
printf(" ");
}
}
printf("\n");
}
for(i = 0; i < n; i++) {
putchar('*');
}
printf("\n");
return 0;
}

2006-07-26 18:37:28 · answer #1 · answered by swami060 3 · 0 0

are you looking for a Java source code or C++ or what?

whatever it is,, all you have to is to print them out.
for example if it is Java then
System.out.println("**********")
System.out.println("*********")
System.out.println("*******")

and so on.. or use arrays or for loops

2006-07-27 01:07:10 · answer #2 · answered by JoToCo 3 · 0 0

fedest.com, questions and answers