Skip to main content

Program in C sharp # to merge two numbers and findest nearest vowel to a inputted character ( question from bca previous year question paper very important )

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

namespace npgc
{
   static  class math
    {
        public static string nearest(char ch)
        {
            int i=0;
            int j=(int)ch;

            string ret="";
            char[] arr = {'a','e','i','o','u'};
            for (i=0;i< arr.Length - 1; i++)
            {
                int tmp=(int)(arr[i]);
             int tmp2=(int)arr[i+1];

             if (j < tmp2)
             {
                 int a = j - tmp;
                 int b = tmp2 - j;
               
                 if (a == b)
                     ret += arr[i] +""+ arr[i + 1];
                   
                 else if (a > b)
                     ret += arr[i + 1];
                 else
                     ret += arr[i];

                 return ret;

             }

            }
            ret += arr[arr.Length - 1];
            return ret;

        }
        public static long merge(long a, long b)
        {
            long tmp = b,t=1;
            do{
                tmp = tmp / 10;

                t*=10;

            }while(tmp>0);
            a = a * t + b;
            return a;
        }

    }
}
namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {
            int ch = 1;
            Console.WriteLine("Enter 1 for merge numbers" + "\n" + "Enter 2 for nearest vowel");
            ch = Convert.ToInt32(Console.ReadLine());

            if (ch < 0 && ch > 2)
                return;
            else
            {
                switch (ch)
                {
                    case 1:
                        Console.WriteLine("Enter 2 numbers");
                        long a = Convert.ToInt64(Console.ReadLine());
                        long b = Convert.ToInt64(Console.ReadLine());
                        Console.WriteLine(npgc.math.merge(a, b));
                        break;
                    case 2:
                        Console.WriteLine("Enter a character");
                        string s = Console.ReadLine();
                        Console.WriteLine(npgc.math.nearest(s[0]));
                        break;

                }
            }

            Console.ReadKey();
        }
    }
}


Comments

Popular posts from this blog

unix commands