Yet another C program....

Status
Not open for further replies.

cloud

In Runtime
Messages
408
sorry to keep posting these things, but my teacher just sort of threw me into C, and I'm having trouble. Here' s my problem:

I have to make a program that takes a number from the user , between 0-12. Then posts a string of numbers from 0 to that number. example, if the user puts in 5, it will give:

0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5

Then it stays open and continues until the user puts in a number not between 0-12 then it terminates.

I've been trying and the best i can get is if i put in 5 it gives me:
012345

I've been workin on it for a long time and i'm really getting frustrated.:mad:

Any advice will be welcome, and sorry for all the qestions.
 
cloud,

#include <stdio.h>
int main(void)
{
int no,i,j;
printf ("Enter a number bet 1-12 : ");
scanf("%d",&no);
for(i=0;i<=no+1;i++)
{
for(j=0;j<i;j++)
{
printf ("%d",j);
printf (" ");
}
printf("\n");
}
}
 
Status
Not open for further replies.
Back
Top Bottom