C Program to Print Floyd’s Triangle Using Recursion on Command Line

Hello friends! In this tutorial, I’m going to teach “C Program to Print Floyd’s Triangle Using Recursion on Command Line” to you. Shall I start the tutorial to teach the possibilities below? Let’s go.

C Program to Print Floyd’s Triangle Using Recursion on Command Line

C Program to Print Floyd’s Triangle Using Recursion on Command Line

Source Code

#include <stdio.h>
 
void print_floyd(int, int, int);
 
int main()
{
  int n;
 
  printf("Input number of rows of Floyd's triangle to printn");
  scanf("%d", &n);
 
  print_floyd(1, n, 1);
 
  return 0;
}
 
void print_floyd(int currentRow, int numberOfRows, int numberToPrint) {
  int c;
  if (currentRow > numberOfRows) // Base case
    return;
 
  for (c = 1; c <= currentRow; c++)
    printf("%d ", numberToPrint++);
 
  printf("n");
  print_floyd(++currentRow, numberOfRows, numberToPrint);
}

Final Words

I hope this article helps you to clarify about “C Program to Print Floyd’s Triangle Using Recursion on Command Line“. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks. Thank You!

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment