# Thread: really easy question! help!!!

1. ## really easy question! help!!!

I have a really simple assignment.
My assignment is to write a program that counts from 1...1000 and displays five numbers across the screen prior to adding the newline character \n

Ex:
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15

the only problem i have is to print out only 5 at a time. I can print out one at a time or al at once. Help on printing ony 5 perline?

2. 2 loops, 1 nested in the first. Or a bit of math and 1loop.

3. I have this

Code:
```#include<stdio.h>
int main(void)
{
int num;

num=1;
while (num<1000)
{
printf("%d",num);
num=num+1.0;
}
return 0;
}```

4. I'm not going to give you the answer since it's your assignment, but 1.0 is for floats/doubles (not integers).

I'll be more specific, use 2 for loops, the 2nd runs inside the first which runs from 1 to 1000 inclusive the second counts from 0 to 5 incrementing the first loop as it does, printing each number (from the first loop). Since the 2nd loop runs per 5 numbers the first loop is responsible for printing the newline. Hint: You'll need 2 integer variables.

BTW your program will only print [1, 1000) ie, 1- 999 -- you'd want num <= 1000

5. i think i kinda know what you are saying...
do not be afraid to help me out it is just stupid homework.

6. Okay, my homebrand pseudo-code is as close as you'll get
Code:
```i is an integer
z is an integer

WHILE i <= 1000
FOR z = 0 ; z < 5 ; INCREMENT z   /* I dunno how to do for loops in pseudo :( */
PRINT i
INCREMENT i
ENDFOR
PRINT "newline"
ENDWHILE```
I suppose you could use 2 for loops, 2 while loops or 1 while and 1 for

7. thanks, but we have not learned how to do for loops yet. I am starting to wonder if my retarted instructor gave us a program on something we have not learned yet.

ANYONE ELSE WNA TOT HELP A LOST GUY IN THIS!!!!!!!!!!!!!!

8. No-one is going to do your homework for you, seriously (not to mention it's against this boards' rules).

If you've learnt while loops but not for loops you can still easily do it.

Code:
```i is an integer
z is an integer

WHILE i <= 1000
z = 0
WHILE z < 5
PRINT i
INCREMENT i
INCREMENT z
ENDWHILE
PRINT "newline"
ENDWHILE```
Seriously, I can't give it away anymore.

9. "head falls on keyboard"
"thinks dirty tought about programing instructor"

10. ok well thanks for your help anyways. I will experiment around with another while loop.
Thanks

11. more help? please?...:[

12. We can't, it's against the rules -- you're the one in the class not us

If we help you any more you'd have the solution. You should be able to look at the psuedo-code in post #8 and work out that, INCREMENT i means ++i in C, just as
Code:
`WHILE i <= 1000 ... ENDWHILE`
is
Code:
`while(i <= 1000) {  ...  }`
in C.

13. Ok first of all i have to most craziest professor in the world he sucks!!! HE does not do s***. He comes to class and ask us if we have questions and tells us to read a booksa dn gives us homework assignments like this one here that has stuff the book does not talk about.
So lets see!

Code:
```#include<stdio.h>
int main(void)
{
int num; /*defines stupid num thjing*/
int ???????   /*I NEED TO DEFINE SOMETHING HAVE NO IDEA WHAT*/
num=1; /*makes it one the starting place*/
while (num<1000) /*from 1-1000 thats where i want to go...*/
while(WHAT THE HECK GOES IN HERE) /*i need something that will make it print out only 5 per line! BUT NOOO THIS STUOID BOOK WONT TELL ME S###*/

{
printf("%d",num);  /*PRINTS OUT THE S****/
num=num+1.0;     /*INCREMENTS THE THINGY*/
}
return 0;    /*Return*/
}```

14. Being agressive won't give you answers. And maybe you should read what people are writing, there's good advice out there in this topic...

Let's say you have to print numbers from 1 to 1000. And let's says you have to print something like

1,2,3,4,5,'\n',6...

So, everytime the current number is a multiple of 5, you have to print a '\n' after that character, else you print a comma. This translate to:

Code:
```printf("%d", currentNumber);
if (currentNumber % 5 == 0)
{
putchar('\n');
}

else
{
putchar(',');
}```
Anyway.

Popular pages Recent additions