UVA 834 - Continued Fractions





#include <bits/stdc++.h>
using namespace std;
vector<long long int>v;



int main()
{
    long long int n,d,i,j,r,s;
    //freopen("834.txt","r",stdin);
    //freopen("834out.txt","w",stdout);
    while(cin>>n>>d)
    {
        v.clear();
        while(d>0)
        {
            r=n%d;
            s=n/d;
            v.push_back(s);
            n=d;
            d=r;

        }
        cout<<"[";
        for(i=0;i<v.size();i++)
        {
            if(i==v.size()-1)
            {
                cout<<v[i]<<"]"<<endl;
            }
            else if(i==0)
            {
                cout<<v[i]<<";";
            }
            else
            {
                cout<<v[i]<<",";
            }


        }

    }
    return 0;
}






Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment