9Google AdSense

ACM Problem Solution 10696 - f91

problem

#include<stdio.h>

long int result(long int n)
{
  if(n<=100)
    return(result(result(n+11)));
  else if(n>=101)
    return(n-10);

}
int main()
{
long int n,x;
while(scanf("%ld",&n)==1)
{
    if(n==0)
        break;
    x=result(n);
    printf("f91(%ld) = %ld\n",n,x);

}
return 0;

}

ACM Problem Solution : 10035 Primary Arithmetic


problem
#include <stdio.h>
#include<string.h>>
int main() {
char a[100],b[100];
int lena,lenb,x,y,num1,num2,cry,sum,i,j;
while(scanf("%s%s",&a,&b)==2)
{
    if(a[0]=='0'&&b[0]=='0')
        break;
    lena=strlen(a);
    lenb=strlen(b);
    x=0;
    cry=0;
    for(i=lena-1,j=lenb-1;i>=0||j>=0;j--,i--)
    {
     if(i>=0)
     num1=a[i]-48;
    else num1=0;
    if(j>=0)
     num2=b[j]-48;
     else num2=0;
     sum=num1+num2+x;
        if(sum>9)
        {
        cry++;
        x=sum/10;

        }
        else x=0;
    }
    if(cry==0)
        printf("No carry operation.\n");
    else if(cry==1)
    printf("%d carry operation.\n",cry);

    else
    printf("%d carry operations.\n",cry);

}

return 0;

}