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

Explain what is wrong with this statement? Myname = ?robin?;

0 Answers  


What is the process of writing the null pointer?

0 Answers  


What are the different pointer models in c?

4 Answers  


Is c easy to learn?

0 Answers  


how to swap four numbers without using fifth variable?

2 Answers  






What is the purpose of sprintf?

0 Answers  


What are c header files?

0 Answers  


What is a loop?

0 Answers  


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

0 Answers  


Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.

0 Answers  


what is C?

9 Answers   Syntel,


There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side?

8 Answers   Google,


Categories