Showing posts with label star pyramid c program. Show all posts
Showing posts with label star pyramid c program. Show all posts

4.17.2013

Star Pyramid

Q. print the following star structure as:

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

Ans.

/*c star pyramid program*/
#include<stdio.h>
int main()
{
 int num,n,r,c,z;
 printf("Enter no. of rows : ");
 scanf("%d", &num);
 n=num;
 for(r=1; r<num; r++,n--)
 {
  for(c=1; c<=n; c++)
     printf("*");
  printf("\n");
 }
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
      printf("*");
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Output of star pyramid C program
Figure: Screen shot for star pyramid C program

4.01.2013

Star sequence pyramid

Q. Write a C program to print the following symbol (star) pyramid.

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

Ans.

/*c program for star pyramid*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter no. of rows: ");
 scanf("%d"&num);
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
     printf("*");
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:

Enter no. of rows: 6
*
**
***
****
*****
******

11.19.2012

Star Pyramid

Q. Write a C program to accept the number of rows of pyramid from user and print the correspondence star triangle.
For example,

Enter number by user : 7

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

Ans.

/*c program for star pyramid*/
#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter number of rows : ");
 scanf("%d", &num);
 for(r=1; r<=(num/2)+1; r++)
 {
  for(c=1; c<=r; c++)
    printf("*");
  printf("\n");
 }
 for(r=1; r<=(num/2); r++)
 {
  for(c=r; c<=num/2; c++)
    printf("*");
  printf("\n");
 }
 return 0;
}

The output of above program would be:

Output of star pyramid C program
Figure: Screen shot for star pyramid C program

10.09.2012

Algorithm for star pyramid

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

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

Ans.

C program for above star pyramid at:

click here

Algorithm for above star pyramid as follows:

[star pyramid procedure]
step1: Start
step2: Read number num
step3: [initialize]
       r=1
step4: Repeat step 4 through 10 until num>=r
step5: [initialize]
       c=1 
step6: Repeat step 6 through 8 until c<=r
step7: print */#
step8: c=c+1
       [end of loop step6]
step9: go to next line
step10: r=r+1
        [end of loop step4]
step11: stop
[end of star pyramid procedure]