Algoritmo soma de fatoriais
Por: Amanda Bittencourt • 22/9/2015 • Ensaio • 271 Palavras (2 Páginas) • 279 Visualizações
#include <stdio.h>
#include <stdlib.h>
long long unsigned calcfat(int n){
int i;
long long unsigned fat=n;
if(n==0) return 1;
for(i=1;i<n;i++){
fat *= i;
}
return fat;
}
int main(){
int i, x, y;
long long unsigned n[25];
for(i=0;i<=20;i++){
n[i] = calcfat(i);
}
while(scanf(" %d %d", &x, &y)!=EOF){
printf("%llu\n",n[x]+n[y]);
}
return 0;
}
Algoritmo novo
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(){
int T, i, tam, num;
long long unsigned int N = 0, P = 0;
char NK[30];
scanf(" %d" , &T);
while(T>0){
scanf("%d%s", &num , NK);
tam = strlen(NK);
N=num;
i = 1;
while(((num-(tam*i))>0) ){
P = (num-(tam*i));
N = N*P;
i++;
}
printf("%llu\n" , N );
T--;
}
return 0;
}
#include <stdio.h>
float p(int i, int j, float S){
if(i<=99) return (S + ((i+2)/(j+1)) + p(i+2,j+1, S)); else return (S);
}
int main()
{
printf("%0.0f" , p(1,1,0));
return 0;
}
#include <stdio.h>
...