Write a program to give following output.....
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********
Answer Posted / prakash
int main()
{
int i, j, star, space, n, middle;
printf("Enter the max. number of stars in a line:");
scanf("%d", &n);
printf("Output:\n");
star = n/2;
space = 1;
middle = n/2 + 1;
for (j = 1; j <= n; j++)
printf("*");
printf("\n");
for (i = 2; i <= (n - 1); i++)
{
for (j = 1; j <= n; j++)
{
if ((j >= (star + 1)) &&
(j <= (star + space)))
{
printf(" ");
}
else
{
printf("*");
}
}
// calculate a and b
if (i < middle)
{
star -= 1;
space += 2;
}
else
{
star += 1;
space -= 2;
}
printf("\n");
}
for (j = 1; j <=n; j++)
printf("*");
printf("\n");
return 0;
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
How was c created?
What is difference between array and pointer in c?
What are the advantages of using Unions?
What is wrong with this code?
Are negative numbers true in c?
Difference between Function to pointer and pointer to function
How can this be legal c?
Difference between exit() and _exit() function?
The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.
Mention four important string handling functions in c languages .
Explain what are the __date__ and __time__ preprocessor commands?
is it possible to create your own header files?
What is a const pointer?
What is the difference between the = symbol and == symbol?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above