How would I go about doing this. Could somebody kind of get me started. I already know like how to prompt for the value and stuff. I basically just need help with the second bullet. But how do I go about having it print the right number of dollar signs in the right row?
Thanks for any help.
Write a program that prints a user-specified number of dollar signs ($) arranged in a triangle.
- Prompt the user to enter the total number of rows to print.
- The triangle array should be printed out with the first row with a single $, the second row (when the number of rows is 2 or bigger) with $$, etc.
-Row requests with zero or a negative number of rows should be rejected with a firm, but polite error message.
This is what I have so far:
#include <stdio.h>
/* function main begins program*/
int main()
{
int x;
int N;
printf("Please enter the number of rows you would like:"); /*prompt for number of rows*/
scanf("%d",&N); /*read number of rows*/
if(N<0) {printf("The number you entered is invalid, please enter a number greater than zero.\n");
return 0;
}
for(x=0; x<=N; x++) {printf("$");
}
for(N=0; x=N; N++) {printf("\n");
}
return 0;
}
Thanks for any help.
Write a program that prints a user-specified number of dollar signs ($) arranged in a triangle.
- Prompt the user to enter the total number of rows to print.
- The triangle array should be printed out with the first row with a single $, the second row (when the number of rows is 2 or bigger) with $$, etc.
-Row requests with zero or a negative number of rows should be rejected with a firm, but polite error message.
This is what I have so far:
#include <stdio.h>
/* function main begins program*/
int main()
{
int x;
int N;
printf("Please enter the number of rows you would like:"); /*prompt for number of rows*/
scanf("%d",&N); /*read number of rows*/
if(N<0) {printf("The number you entered is invalid, please enter a number greater than zero.\n");
return 0;
}
for(x=0; x<=N; x++) {printf("$");
}
for(N=0; x=N; N++) {printf("\n");
}
return 0;
}
