Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

shorting algorithmS

2193


What is meant by operator precedence?

1095


what is use of malloc and calloc?

1844


if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0

1880


Can math operations be performed on a void pointer?

960


why we wont use '&' sing in aceesing the string using scanf

2308


Differentiate abs() function from fabs() function.

957


can we have joblib in a proc ?

2226


What is difference between scanf and gets?

1165


Do you know the use of fflush() function?

1011


Explain what is the difference between functions abs() and fabs()?

1097


What is static volatile in c?

969


What is the use of typedef in structure in c?

916


Why is sprintf unsafe?

997


What is c definition?

1191