0

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 :)

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Liyaan
-1

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");
	}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.