Answer to Question #10866 in C++ for Jo

Question #10866
Write a program (in C language not C++) which draws an “x” of user specified height. If the user typed 7,
the following series of ‘*’ characters would be drawn (without line
numbers):
1 2 3 4 5 6 7
1 * *
2 * *
3 * *
4 *
5 * *
6 * *
7 * *
1
Expert's answer
2012-06-15T09:41:39-0400
#include <stdlib.h>
#include <conio.h>
int main()
{
char
arrayofstar[100][100];
int height=0;
printf("Enter height:
");
scanf("%d",&height);
int k=height-1;
int count=0;
for(int
i=0;i<height;i++){

for(int
j=0;j<height;j++){
arrayofstar[i][j]='*';
if(i==j){
printf("%c",arrayofstar[i][j]);
}
if(i==count
&& j==k){
printf("%c",arrayofstar[i][j]);
}
else{
printf("
");
}
}
printf("\n");
count++;
k--;
}
getch();
return
0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS