Q. Write a C program to floyd algorithm number triangle in C as:
2 3
4 5 6
7 8 9 10
Ans.
/* c program for floyd algorithm number triangle */
#include<stdio.h>
int main()
{
int r,c,n,x=1;
printf("Enter No. Of rows : ");
scanf("%d", &n);
for(r=1; r<=n; r++)
{
for(c=1; c<=r; c++,x++)
printf(" %d",x);
printf("\n");
}
getch();
return 0;
}
/*************************************************************
The output of above program would be:
**************************************************************/
Figure: Screen shot for Floyd algorithm number triangle C program |
A
B C
D E F
G H I J
9
8 7
6 5 4
3 2 1 0
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
#include
ReplyDeletevoid main()
{
int i, j, k, x = 1;
for(i = 1; i <= 4; i++)
{ for(j = 1; j <= 4 - i; j++)
printf(" ");
for(k = 1 ; k <= i; k++, x++)
printf("%d ", x);
printf("\n");
}
}
algorithms and flowcharts for 31 lab programs
ReplyDeleteCan you please give the same program but in the form:
ReplyDeletea
b c
d e f
g h i j k
@Maya,
Delete//Your required program as:
#include"stdio.h"
int main()
{
int n=4,x='a';
char r,c;
for(r='a'; n>=1; n--,r++)
{
for(c='a'; c<=r; c++,x++)
printf(" %c",x);
printf("\n");
}
getch();
return 0;
}
Can you please give the same program but in the form:
ReplyDelete0 1 2 3 4
1 2 3 4
2 3 4
3 4
#include
Deletevoid main()
{
int i,j,n;
int x=0,y=0;
printf("Enter the no of line");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
x=y;
for(j=i;j<=n;j++,x++)
printf("%d ",x);
y++;
printf("\n");
}}
C program to print the pyramid of digits
ReplyDeleteprint new line should come out of for loop
ReplyDeletethen only v ill get triangle
R
ReplyDeleteRI
RIZ
RIZA
RIZAL
how about this,,
just print without input .
if i enter 5
ReplyDelete5
4 3
2 1 0
-----------------------------------------
if i enter 16
16
15 14
13 12 11
10 9 8 7
6 5 4 3 2
# Mavuri Yasoda
DeleteYour required above Floyd number pattern C program source code at:
http://cprogrammingcodes.blogspot.com/2016/07/reverse-floyd-number-pattern-c-program.html
Can help me..writing same prog using while loop
ReplyDeleteMohd Imran,
DeleteYour required Floyd Triangle C program using while loop source code as :
#include"stdio.h"
int main()
{
int r,c,n,x=1;
printf("Enter No. Of rows : ");
scanf("%d", &n);
r=1;
while(r<=n)
{
c=1;
while(c<=r)
{
printf(" %d",x);
c++;
x++;
}
r++;
printf("\n");
}
getch();
return 0;
}
Hope its help you. Thanks for improving C language community.
1
ReplyDelete12
123
1234
Your required above number pattern source code :
Deletehttp://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html
1
ReplyDelete12
123
1234
#Ambarish Banerjee
DeleteYour required number pattern design c program source code :
http://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html
More formally, a triangular number counts the number of symmetric objects that fits in the form of an equilateral triangle. The sequence of all triangle numbers is: 1, 3, 6, 10, 15, 21, … As shown here all those numbers form perfect equilateral triangles. You can read this article to understand more about triangular numbers.
ReplyDeleteYour mission, should you choose to accept it:
Take an integer input from the user, print a list of all even triangular numbers less than or equal to the input number. Additionally, only for the largest even triangular number you found, you should print all (odd and even) triangle numbers in a shape of a triangle as illustrated below.
01
** 03
** ** 06
** ** ** 10
** ** ** ** 15
** ** ** ** ** 21
** ** ** ** ** ** 28