Write a program in c using only loops to print *
* *
* *
*******

Answers were Sorted based on User's Feedback



Write a program in c using only loops to print * * * ..

Answer / evr

This is the generic code for printing above such pattern. You can print the above pattern for different number of rows by entering different value during run time

#include<stdio.h>
int main()
{
int n, i, j;
printf("Enter the number of rows:");
scanf("%d",&n);
for(i=0;i<n;i++)
if(i!= n-1)
{
for(j=1;j<=2*n;j++)
{
if(j==n-i || j==n+i)
printf("*");
else
printf(" ");
}
printf("\n");
}
else
for(i=0;i<2*n-1;i++)
printf("*");
return 0;
}

Thank you......

Is This Answer Correct ?    0 Yes 0 No

Write a program in c using only loops to print * * * ..

Answer / veera

#include<stdio.h>
#include<math.h>
main()
{
clrscr();
printf("*");
printf("\n");
printf("* *");
printf("\n");
printf("* *");
printf("\n");
printf("*******");
getch();
}

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Interview Questions

What are volatile variables?

1 Answers   Mind Tree,


what is used instead of pointers in java than c?

1 Answers   Vuram,


what is the difference between while and do while?

2 Answers  


What are advantages and disadvantages of recursive calling ?

12 Answers   College School Exams Tests, Evolving Systems, HP, Jyoti Ltd, Sage, Wipro,


What is the Difference between Class and Struct?

10 Answers   Motorola,






What is the difference between union and anonymous union?

0 Answers   Hexaware,


Can a binary search tree be used as an index? If yes, how? Explain

0 Answers   TCS,


What is the meaning of ?

0 Answers  


Explain what will the preprocessor do for a program?

0 Answers  


What was noalias and what ever happened to it?

0 Answers  


What is the benefit of using an enum rather than a #define constant?

0 Answers  


who developed c and why he developed c?

5 Answers  


Categories