Show as many possible combinations

Asked

Viewed 57 times

1

#include <stdio.h>

void main() {

    int x=10;
    int y;
    int numero;

    printf("quantos digitos tem sua senha: ");
    scanf("%d", &numero);

    y = numero * x;

    printf("sua senha tem %d combinacoes possiveis!", y);


}

For now I have arrived at this, I need to make a program q the user put how many digits have his password and the program calculate the possible combinations based on as many digits q the user put.

Remembering that the password is composed only by numbers.

Example: the user puts the value 1, the program must say q there are 10 combinations (0,1,2,3,4,5,6,7,8,9).

  • 1

    And what is your doubt?

  • Your question is about combinations or how to apply the combinations in the code? If it is the second option, which part you are unable to apply?

  • If the digits can be repeated in the password then you can have 10 x possibilities. If repetitions cannot occur then you can have 10! / (10-x)! possibilities (simple arrangement of mathematics).

1 answer

1


You can do it this way:

#include <stdio.h>
#include <math.h>    

void main() {

        int y, numero;

        printf("quantos digitos tem sua senha: ");
        scanf("%d", &numero);

        y = pow(10,numero); //elevando 10 (0,1,2...8,9) pela quantidade de numeros

        printf("sua senha tem %d combinacoes possiveis!", y);


    }

Not forgetting to include #include <math.h> to use the function pow()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.