Prymide of letters in c with recursion

hey i would appreciate some help with this problem i need to write a code in c that receive a number of Rows from the user and prints prymide of letters using recursion for example:
Please enter a number : 4
A
AB
ABC
ABCD

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

here is my code, i try to do it ASCII but it didnt work



#include<stdio.h>
void func1(int n);


int main( )
{

    int n;
    printf("Enter how many lines u want to print ? ");
    scanf("%d",&n);
        func1(n);
        printf("\n");
        return 0;

}
void func1(int n)
{
    char i=65;
    if(n==0)
        return;
    else
    {
        func1(n-1);
        for(; i<= n; i++)
            printf("%c ",i);
        printf("\n");
    }
}

This is actually pretty close. I added some comments and formatting.

#include<stdio.h>
// I'd  use a better name here. printAlphabet maybe?
void func1(int n);

// Usually, we put void as the args if there are none
//       \/ right here
int main(void) {
  int n;
  printf("Enter how many lines u want to print ? ");
  scanf("%d", &n);
  func1(n);
  printf("\n");

  return 0;
}

void func1(int n) {
  // Why 65? (I know why but it should be a comment or just the char here)
  char i = 65;

  // Rule of thumb, you should cover *all* numbers, so you should also put negative numbers here
  if (n == 0) {
    return;
  } else {
    func1(n - 1);
    // Two strange things here
    // 1) You should initialize i here. You don't need i outside of the loop.
    //    Its uncommon that you should have a for loop with a missing part of the head.
    // 2) You have your loop condition as i <= n, but what happens when you call with n = 1?
   //     Your bound should probably have something to do with the character code for A
    for (; i <= n; i++) {
      printf("%c ", i);
      printf("\n");
    }
  }
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.