[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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s