In: Computer Science
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below
Enter an integer
5 // User enters 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Bye
Done in C programming as asked
If you need any modifications, please comment.
I have explained everything in the comments.
#include <stdio.h>
int main()
{
int i,j,n;
printf("Enter the number: ");/* Prints statement */
scanf("%d",&n);/* takes input from user */
for(i=0;i<=n;i++)# /*for loop */
{
for(j=1;j<=i;j++)/*for loop */
{
printf("%d",i); /* prints the values */
}
printf("\n");
}
printf("Bye");/* prints Bye at the end */
}
If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.
Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.