Combination Program

Solved
jesper1 Posted messages 69 Status Membre -  
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   -
Hello,
I would like to write a program in C that displays the different combinations you can make with the digits 0 1 2 3 4 5 6 7 8 9. The same digit can be repeated up to ten times starting from 0000000000 and then 0000000001, but so far I have only managed to write a program that displays the numbers between 0 and 9999999999 (the program works and has been running for four hours ????) but that's not really what I'm looking for, so... can you help me?

2 réponses

yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 587
 
Hello,

can you share your program, using code tags: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

can you also explain the result you expect, and how it differs from the result you are getting, perhaps with an example?
maybe share the exact statement of the exercise?
0
jesper1 Posted messages 69 Status Membre
 
It's a very simple program based on the "for" loop.

 #include <stdio.h> #include <stdlib.h> main() { int i ; for ( i=0 ; i<=9999999999 ; i++ ) { printf ("%d\n", i) ; } } 


So basically, that's it. By running this code, the program starts listing all the numbers from 0 to 9999999999. What I want is for it to list all the ten-digit numbers (all possible combinations) that can be created with the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, considering that the same digit can be repeated up to 10 times. Basically, it will start with 0000000000 and end with 9999999999.
This exercise is personal.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587 > jesper1 Posted messages 69 Status Membre
 
you do not explain precisely how what you obtain diverges from what you wish to obtain. maybe show an example.
the program clearly does what it was written for. what is the purpose of the personal exercise? how did you end up writing a program that seems to do not what you want to do?
do you simply want to display the insignificant zeros? if so, read this: https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160&viewFallbackFrom=vs-2019
0
jesper1 Posted messages 69 Status Membre > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
The program I wrote does what it's supposed to do and lists the numbers between 0 and 9999999999. I'm just saying that's what I managed to do. What I want is a program that takes the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and combines them in different ways to form a ten-digit number (from 0 to 9). Basically, I want a program that lists all the ten-digit numbers that can be formed with 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The first numbers in the list should be 0000000000 followed by 0000000001 followed by 0000000002 followed by 0000000003 followed by 0000000004 and so on. The last ones will be 9999999997 followed by 9999999998 and finally 9999999999.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 587 > jesper1 Posted messages 69 Status Membre
 
don't you get exactly what you want, apart from non-significant zeros?
0
jesper1 Posted messages 69 Status Membre > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
The problem is precisely these non-significant zeros. I was wondering if it's possible to display them like everything else. For example, the first number it shows me is 1, but since I want a number with 10 characters, can it instead show me "0000000001" instead of just "1"?
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 587
 
do you want to get this?
main() { int i1,i2 ; for ( i1=0 ; i1<=9 ; i++ ) { for ( i2=0 ; i2<=9 ; i++ ) { printf ("%d%d\n", i1, i2) ; } } }
0