Search This Blog

Showing posts with label Easy Uva Code. Show all posts
Showing posts with label Easy Uva Code. Show all posts

Sunday, 14 June 2015

10035-Primary Arithmatic

 Problem Link:Click Here!!

 

Problem Solution:

#include<stdio.h>
int main(void){

long long int a,b,res,c,d;
int o;

while(scanf("%lld %lld",&a,&b)==2){

o=0;
res=0;

if(a==0 && b==0)break;

else{
        if(a<b){c=a;
        a=b;
        b=c;
     }

      while(a!=0){
       c=a%10;
       a=a/10;
       d=b%10;
       b=b/10;
       res=c+d+res;

      if(res>=10){o++;
               res=res/10;
                  }

       else res=0;
       }

if(o==0)printf("No carry operation.\n");
        else if(o==1)printf("%d carry operation.\n",o);
                 else if(o>1)printf("%d carry operations.\n",o);
              }
      }
return 0;
}

369 - Combinations

 Problem Link: Click Here!!

 Solution:


#include <stdio.h>

int main (void) {
    double m,n,a,b,c;

    while(scanf("%lf %lf",&m,&n)==2 && m && n){


        c=1;
        a=m;
        b=m-n;

        if(b>n) b=n;

        while(b) {
            c = c*(a/b);
            a--;
            b--;
        }


        printf("%.0lf things taken %.0lf at a time is %.0lf exactly.\n",m,n,c);

    }

    return 0;
}

Saturday, 13 June 2015

11219 - How old are you?

 Problem Link:Click Here!!


Solution:

#include<stdio.h>
int main()
{

int i,t,y,y1,y2,m1,m2,d1,d2;

scanf("%d",&t);

i=1;

while(i<=t){

scanf("%d/%d/%d",&d1,&m1,&y1);
scanf("%d/%d/%d",&d2,&m2,&y2);

     y=(y1-y2);

            if(m1<m2)
                y--;

            else if(m1==m2)
            {
                if(d1<d2)
                y--;
            }

            if(y<0)
                printf("Case #%d: Invalid birth date\n", i );
            else if(y>130)
                printf("Case #%d: Check birth date\n", i);
            else
                printf("Case #%d: %d\n",i,y);

    i++;

  }

return 0;

}