AprendendoC 0 Posted April 3, 2011 Report Share Posted April 3, 2011 galera e o seguinte.... Desenvolva um programa que solicite um número ao usuário e exiba o seu fatorial na tela. nao to conseguindo fazer o program exibir o fatorial..... ele teria que aparecer assim: o fatorial de 10 é: 10x9, 10x8, 10x7.............. mas ele esta so exibindo o resultado final... int n,fat = 1,x; printf("\nEntre com um numero inteiro: "); scanf("%d",&n); x = n; while(x > 1) { x--; fat = x * fat; } fat = n * fat; printf("\nO fatorial de %d e %d \n\n",n,fat); agradeço a ajuda de vcs! Link to post Share on other sites
Localhost 3 Posted April 3, 2011 Report Share Posted April 3, 2011 Tens de meter um printf dentro do ciclo, não? here since 2009 Link to post Share on other sites
AprendendoC 0 Posted April 3, 2011 Author Report Share Posted April 3, 2011 coloquei um printf dentro do laço, ele esta imprimindo mas nao como devia.... em vez de ele imprimir 10*9 10*8........ ele esta imprimindo 10 10 10 10 e nao mostra o resultado... 🤔 Link to post Share on other sites
kareka 0 Posted April 3, 2011 Report Share Posted April 3, 2011 int n,fat = 1,x; printf("\nEntre com um numero inteiro: "); scanf("%d",&n); x = n; printf("%d*",x); while(x >= 1) { x--; fat = x * fat; if(x==1) printf("1"); else printf("%d*",x); } printf("\n%d!=%d\n\n",n,fat); Tenta assim . <?php include("assinatura.txt"); ?> Link to post Share on other sites
BrunoMoreira 0 Posted April 6, 2011 Report Share Posted April 6, 2011 Pelo que percebi, pretende calcular o factorial de um número, não é assim?? Básicamente o factorial é isto: Factorial de x: x! = 1*2*3*...*x onde o x é um número inteiro positivo, incluindo o zero. #include <stdlib.h> #include <stdio.h> int main() { unsigned int n,i,f; scanf("%d",&n); for(i = 1,f = 1; i <= n; i++) { f*=i; } printf("%d\n",f); system("Pause"); return 0; } Espero ter ajudado. Aluno CIC 11ºIF 2010/2011 Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now