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

Write a program which returns the first non repetitive character in the string?

0 Answers   Expedia,


Why is void main used?

0 Answers  


How can you access memory located at a certain address?

0 Answers  


Determine if a number is a power of 2 at O(1).

2 Answers  


What is a #include preprocessor?

0 Answers  






code snippet for creating a pyramids triangle ex 1 2 2 3 3 3

4 Answers  


int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }

1 Answers  


What is the difference between printf and scanf in c?

0 Answers  


Write programs for String Reversal & Palindrome check

0 Answers   TISL,


how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.

2 Answers  


write a function for strtok()??

2 Answers   Verifone,


What is the maximum length of an identifier?

0 Answers  


Categories