[ACM Timus] 1083. Factorials!!! [c]

Problem link: 1083. Factorials!!!

 
http://acm.timus.ru/problem.aspx?space=1&num=1083
 
[c]
#include<stdio.h>
void factorial(int a, int j);
int main()
{
int a,i,j=0;
char b[21];
scanf("%d %s",&a,b);
for(i=0;i<20;i++){
if(b[i]==’!’)
j++;
else if(b[i]==’\0’)
break;
}
factorial(a,j);

return 0;
}
void factorial(int a, int j){
int k,m;
m=a;
for(k=1;;k++){
if((m-k*j)<=0)
break;
a=a*(m-k*j);
}

printf("%dn",a);
}

[/c]

Advertisements