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

difference between my-strcpy and strcpy ?

3 Answers   Geometric Software, IIM, Infosys,


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

0 Answers  


wat is the meaning of c?

9 Answers   CTS, IBM, Wipro,


Explain the use of fflush() function?

0 Answers  


What do you mean by command line argument?

0 Answers   TCS,






Given a string write a program to print all alphabetical characters in the order of their occurance first,followed by the sum of the numeric characters then followed by the special characters in the order of their occurance.

1 Answers   College School Exams Tests, Wipro,


string reverse using recursion

0 Answers   Mind Tree,


void main() { int x=25,y=32; clrscr(); x=x++ + y++; y=++x + ++y; printf("%d%d",x,y); }

5 Answers  


Can I pass constant values to functions which accept structure arguments?

2 Answers  


main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); } what is the output?

10 Answers   Ramco,


Do you know null pointer?

0 Answers  


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

0 Answers  


Categories