Friday, December 13, 2013

Write a C program to print the following star program. Also write down the algorithm

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
     printf("*");
  printf("\n");
 }
 getch();
 return 0;


Output

*
**
***
****
*****

step1: num<--0, r<--0, c<--0
step2: Read number num
step3: Repeat step 4 for r=1,2,3....num
step4: Repeat step 5 for c=1,2....r
                    Begin

        print "*"
                    End
step8: 
step9: go to next line
step10: r=r+1
        [end of loop step4]
step11: stop
 

No comments:

Post a Comment