Sunday, 5 January 2014

Continuous Fractions in C# Console Application

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
   
    {
        static void Main(string[] args)
        {
            int a, b, i = 0, m, d, j, si;
            int[] ar = new int[10];
            Console.WriteLine("ENTER THE dividend");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("ENTER THE divisor");
            b = int.Parse(Console.ReadLine());
            try
            {
                while (a > b)
                {
                    d = a / b;
                    ar[i] = d;
                    i++;
                    m = a % b;
                    a = b;
                    b = m;
                }
            }
            catch (Exception ee)
            {
            }           
            si = ar.Length;           
                for (j = 0; j < si; j++)
                {
                    Console.WriteLine("{0} +  1", ar[j]);
                    Console.WriteLine("   ________");
                }
                Console.WriteLine("   1");
           
        }
    }
}

No comments:

Post a Comment