Using nested for loops, how do I write a program that asks the user to input an integral number and then displays a diagonal line with that many dots on the console screen starting in the column?


An input of 4 would display four diagonal periods, while an input of 5 would display five diagonal periods, etc.

.
[space].
[space][space].
[space][space][space].

other info: Write the program in such a way that the character printed diagonally as well as the leader character(s) preceding it may be changed easily without digging through the actual code to find them, that is, use macros to define these characters.

Thanks for your help :)

this will display N diagonal periods...

#include<stdio.h>

main() {
	int i,j,number;
	
	printf("Enter an integer: ");
	scanf("%d",&number);
	
	for (i=1;i<=number;i++) {
		for (j=1;j<=i;j++) {
			if (j==i) {
				printf(".");
			}
			else {
				printf(" ");
			}
		}
		printf("\n");
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.