প্রোগ্রামের বিবরণ
ফ্লয়েডের ত্রিভুজ হল প্রাকৃতিক সংখ্যার সমকোণী ত্রিভুজাকার বিন্যাস, কম্পিউটার বিজ্ঞান শিক্ষায় ব্যবহৃত হয়। এর নামকরণ করা হয়েছে রবার্ট ফ্লয়েডের নামে। উপরের বাম কোণে 1 দিয়ে শুরু করে ত্রিভুজের সারিগুলি পরপর সংখ্যা দিয়ে পূরণ করে এটি সংজ্ঞায়িত করা হয়।
1 15 14 13 12 11 2 3 10 9 8 7 4 5 6 6 5 4 7 8 9 10 3 2 11 12 13 14 15 1 Floyd's Triangle Reverse of Floyd's Triangle
অ্যালগরিদম
Floyd’s Triangle- প্রিন্ট করতে
Accept the number of rows to print the Floyd’s Triangle Print value 1 for the Row 1 Print two values 2 and 3 in the next row Print three values 4, 5 and 6 in the next row Repeat till the number of rows specified
ফ্লয়েডের ত্রিভুজের বিপরীত মুদ্রণ করতে -
Accept the number of rows to print the reverse of Floyd’s Triangle Print the values in the reverse order as specified in the reverse of Floyd’s Triangle
উদাহরণ
/*Program to print the Reverse of Floyd's Triangle*/
#include<stdio.h>
int main() {
int r,c=1;
int rows,revrows,r1,c1,d;
clrscr();
printf("Enter number of rows to print the Floyd's Triangle: ");
scanf("%d", &rows);
printf("\n");
for (r=1;r<=(rows*(rows+1))/2;r++){
printf("%d ",r);
if(r==(c*(c+1))/2){
printf("\n");
c++;
}
}
printf("\n\n");
/*Printing the Reverse of Floyd's Triangle*/
printf("Enter number of rows to print the reverse of Floyd's Triangle: ");
scanf("%d",&revrows);
printf("\n\n");
printf("Reverse of Floyd's Triangle\n");
printf("\n\n");
d = (revrows*(revrows+1))/2;
for(r1=revrows;r1>=1;r1--){
for(c1=r1;c1>=1;c1--,d--){
printf("%4d", d);
}
printf("\n");
}
getch();
return 0;
}
আউটপুট
