Jump to content

Mostrar divisores e factorial


tuasite
 Share

Recommended Posts

Boas pessoal, agradecia se possivel a vossa ajuda estou a fazer este codigo para calcular o divisor e o factorial de um numero recorrendo à sub programação mas nao me sai do ciclo esta me sempre a pedir para digitar um numero, o codigo é o seguinte:

int factorial(int n)
{
    int fac,i;
    fac=1;
    for (i=2;i<=n;i++);
        fac=fac*i;
    return fac;
}

int mostrardivisores(int n)
{
    int i;
    for (i=1;i<=n/2;i++);
        if (n%i==0)
            printf("%d",i);
            printf("%d",n);
}

int main()
{
    int num,f;
printf("Digite um numero:\n");
scanf("%d",&num);
while (num>=0)
{
        if (num<=0)
        {
	    f=factorial(num);
            printf("Factorial de %d é %d",num,f);
        }
        else
            mostrardivisores(num);
        printf("Digite um numero:\n");
        scanf("%d",&num);
}
return 0;
}

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.