Skip to main content

Posts

Showing posts from March, 2019

URI problem "1151 - Easy Fibonacci" solution

#include<stdio.h> int main() {     int i,f1=0,f2=1,next,n;     scanf("%d",&n);     for(i=0;i<n-1;i++)     {         if(i<=1)         {             next=i;         }         else         {             next=f1+f2;             f1=f2;             f2=next;         }         printf("%d ",next);     }     printf("%d\n",next+f1);     return 0; }

URI problem "1172 - Array Replacement I" solution

#include<stdio.h> int main() {     int i,X[10];     for(i=0; i<10; i++)     {         scanf("%d",&X[i]);     }     for(i=0; i<10; i++)     {         if(X[i]<=0)         {             X[i]=1;         }     }     for(i=0; i<10; i++)     {         printf("X[%d] = %d\n",i,X[i]);     }     return 0; }

URI problem "1134 - Type of Fuel" solution

#include<stdio.h> int main() {     int a,n,b,x=0,y=0,z=0;     for(n=1;; n++)     {         scanf("%d",&a);         if(a==4)break;         if(a<0||a>4)         {             scanf("%d",&a);         }         if(a==1)         {             x++;         }         else if(a==2)         {             y++;         }         else if(a==3)   ...

URI problem "1159 - Sum of Consecutive Even Numbers" solution

#include<stdio.h> int main() {     int x,p,i,j,s,n;     for(i=1;;i++)     {         scanf("%d",&x);         if(x==0)break;         else if(x%2==0)         {             s=0;             for(j=x;j<=x+8;j=j+2)             {                 s+=j;             }             printf("%d\n",s);         }         else if(x%2!=0)         {   ...

URI problem "1158 - Sum of Consecutive Odd Numbers III" solution

#include<stdio.h> int main() {     int n,x,y,i,p,a,b,s;     scanf("%d",&n);     for(i=1; i<=n; i++)     {         s=0;         p=0;         scanf("%d %d",&x,&y);         if(x%2==0)         {             p=(((y*2)+x)-1);             for(a=x+1; a<=p; a=a+2)             {                 s+=a;             }         }         else if(x%2!=0)       ...

URI problem "1154 - Ages" solution

#include<stdio.h> int main() {     double n,i,a=0,b=0,x,avg;     for(i=1;; i++)     {         b++;         scanf("%lf",&n);         a+=n;         if(n<0)         {             a=a-n;             break;         }     }     x=b-1;     avg=((a*1.00)/x);     printf("%.2lf\n",avg);     return 0; }

URI problem "1150 - Exceeding Z" solution

#include<stdio.h> int main() {     int x,y,i,z,q,j=0,s=0,b=0;     scanf("%d",&x);     scanf("%d",&z);     if(x>=z)     {         for(i=1;; i++)         {             scanf("%d",&z);             if(z>x)break;         }     }     for(q=x; j<z; q++)     {         j=j+q;         b++;     }     printf("%d\n",b);     return 0; }