Friday, November 21, 2014

C Fibonacci series pyramid



C Program to print Right Angle Fibonacci Series Pyramid

#include
 #include
int main(void)
{
   int row, column, first_no = 0, second_no = 1, sum = 1;

   for (row = 1; row <= 4; row++)
{
      for (column = 1; column <= row; column++)
  {
         if (row == 1 && column == 1)
    {
            printf("0");
            continue;
         }
         printf("%d\t", sum);

         sum = first_no + second_no;
         first_no = second_no;
         second_no = sum;
      }
      printf("\n");
   }
   return 0;
}

Output

0
1    1
2    3    5
8    13   21    34

Program to print Right Angled Binary Pyramid

#include
#include
int main()
{
int row, column;
for(row=0;row<4 row="" span="">
{
for(column=0;column<=row;column<=row;column++)
{
if((row+column)%2==0)
{
printf("0");
}
else
{
printf("1");
}
printf("\n");
}
return 0;
}

C Program to Print Triangular Sequence Pyramid


#include
#include

void main()
{
   int i, j;
   clrscr();

   for (i = 0; i <= 9; i++)
 {
      for (j = 0; j < (1 + 2 * i); j++)
{
         printf("%d ", i);
      }
      printf("\n");
   }

   getch();
}

C Program to Print Mirror of Right Angled Triangle


#include
#include 
int main()
{
   char ch = '*';
   int i, j, no_of_spaces = 4, spaceCount;

   for (i = 1; i <= 5; i++)
     {
      for (spaceCount = no_of_spaces; spaceCount >= 1; spaceCount--)
    {
         printf("  ");
      }

      for (j = 1; j <= i; j++)
    {
         printf("%2c", ch);
      }

      printf("\n");
      no_of_spaces--;
   }
   return 0;
}

C Program to Print FLOYD triangle


#include
#include
int main()
{

   int i, j, k = 1;
   int range;

   printf("Enter the range: ");
   scanf("%d", &range);

                                                                                                                                                                                                                                                                                 

   for (i = 1; i <= range; i++)
 {
      for (j = 1; j <= i; j++, k++)
 {
         printf("%d", k);
      }
      printf("\n");
   }

   return 0;
}

Output

Enter the range: 4

Floyd's triangle :

1
2 3
4 5 6
7 8 9 10

No comments:

Post a Comment