Simple Function but......I NEED HELP
Hi, I am a beginning Programmer. I do not yet know pointers and was wondering if there was a way to create a loop or what not to help out in my program. I want to put this function in a file by itself, yet I don't even know where to begin. My problem: input: read in a series of intergers consisting of up to nine digits. The function will break the numbers apart and list them in reverse. Example: the numbers 123456789 are entered..
9 8 7
6 5 4
3 2 1
is outputed. How can I do this ??? any help would be greatly appreciated. I think you use 123456789 / 10 and 123456789 %10 but am not sure how to write the function. Thanks
HERE's MY CODE that does'nt work... anyone...
Thanks for the matrix trick. I cannot use it though. I haven't got a clue what it is. The following code sorta does it but it doesn't work right..... does this help? ? ? Thanks again for the help thus far.
____________________________
Code:
int main(void){
int numtosplit,counter,currdig;
printf("\nEnter a positive integer (up to 9 digits in length);");
printf("\nhalt with a non-positive integer:\n");
scanf("%d",&numtosplit);
/* Start outer loop: makes program repeat */
while(numtosplit>0) {
counter=3;
/* Inner Loop */
while(numtosplit >0){
if(counter ==3) {
counter=0;
printf("\n ");
}
currdig=numtosplit%10;
numtosplit=numtosplit/10;
counter++;
return currdig;
}
/* Get new number to split */
printf("\n\n");
printf("\nEnter a positive integer (up to 9 digits in length);");
printf("\nhalt with a non-positive integer:\n");
scanf("%d",&numtosplit);
}
return (0);
}
______________
[I] Code tags added by Kermi3]/I]
New Working/ updated code
Thanks guys soooo much. I got it to work.. It's AWESOME!!! I would like to thank everyone to help. Here is the code.... I left out a Stupid print statement.... LOL :)
Code:
#include <stdio.h>
int main(void) {
int split_num,count,digit;
printf("\nEnter a positive integer (up to 9 digits in length);");
printf("\nhalt with a non-positive integer:\n");
scanf("%d",&split_num);
/* Start outer loop: makes program repeat */
while(split_num>0) {
count=3;
/* Inner Loop */
while(split_num >0){
if(count==3) {
count=0;
printf("\n ");
}
digit=split_num%10;
split_num=split_num/10;
printf("%d ",digit);
count++;
}
/* Get new number to split */
printf("\n\n");
printf("\nEnter a positive integer (up to 9 digits in length);");
printf("\nhalt with a non-positive integer:\n");
scanf("%d",&split_num);
}
return (0);
}