Computer Scientists are Pretty Pessimistic

Showing posts with label UVA Problem Solution. Show all posts
Showing posts with label UVA Problem Solution. Show all posts

Friday, 23 October 2015

UVA 10783 (Odd Sum)

Solution ::

#include <stdio.h>
int main ()
{
    int i,t,a,b,m,n;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        int sum=0;
        scanf("%d %d",&a,&b);
        if(a%2!=0){
            n=a;
        }
        if(a%2==0){
            n=a+1;
        }
        for(m=n;m<=b;m=m+2){
            sum=sum+m;
        }
        printf("Case %d: %d\n",i,sum);
    }
    return 0;
}

UVA 11461 (Square Numbers)

Solution : :

#include <stdio.h>
#include <math.h>
int main ()
{
    int a,b,i,sq,count;
    while(scanf("%d %d",&a,&b))
    {
        count=0;
         if(a==0&&b==0)
        {
            break;
        }
        for(i=a;i<=b;i++)
        {
            sq=sqrt(i);
            if(i==sq*sq)
            {
                count++;
            }
        }
       printf("%d\n",count);
    }
    return 0;
}