Help in my 1st code

Question:

#include<stdio.h>
int main(){
    int n,i,j;
    printf("Enter the number of rows: ");
    scanf("%d",&n);
     int a=1;
    for(i=1;i<=n;i++){
        for(j=1;j<=i;j++){
        
              printf("%d",a);
              a++;
    }
      printf("\n");
        }
  return 0;
  }

Repl link:

what kind of issue you’re experiencing/help you need right now?
can you elaborate and explain further?

4 Likes

First off, I would define i & j inside their respective loops rather than all at once, just for clarity sake. Also, proper indentation is very important for readability.

#include <stdio.h>

int main() {
	int n;
	printf("Enter the number of rows: ");
	scanf("%d", &n);

	int a = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			printf("%d", a);
			a++;
		}
	printf("\n");
	}
	return 0;
}
1 Like

Use the ghostwriter ai, you can ask it to review your project for errors or suggestions, it will also restructure the alignment where needed, just be careful what you use it for, the usage is limited.

AI heavily hallucinates, and I strongly discourage it’s use as a new programmer’s only source of help.

5 Likes

I 100% agree. AI is, in my opinion, nothing more than a tool. Yes, it can definitely help you and it can fill in small gaps, but when it comes to a more significant gap in your knowledge or a more complex task, it often falls short.

In the programming world, beginners sometimes have ‘mentors’. I personally think this idea of just talking with someone more experienced (not an AI) could be a really good way of improving, so if you know someone, maybe try talking with them. :smile:

4 Likes