Showing posts with label interview questions. Show all posts
Showing posts with label interview questions. Show all posts

Saturday, 30 July 2016

Star Programming 7

Introduction


Hi guys, today I will show you how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.

My previous article was Star Programming 6

static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = num; i>0; i--)
    {
        for (int k = i; k < num; k++)
        {
            Console.Write(" ");
        }
        for (int j = 0; j < i; j++)
        {
            Console.Write("*");
        }
        Console.WriteLine();
    }
}

Star Programming 6

Introduction


Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.

My previous article was Star Programming 5

static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < num; i++)
    {
        for (int k = num-1; k > i; k--)
        {
            Console.Write(" ");
        }
        for (int j = 0; j <= i; j++)
        {
            Console.Write("*");
        }
        Console.WriteLine();
    }
}

Star Programming 5

Introduction


Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.

My previous post was Star Programming 5 


static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < num; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if ((i + j) % 2 == 0)
                Console.Write("0");
            else
                Console.Write("1");
        }
        Console.WriteLine();
    }
}

Star Programming 4

Introduction


Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.

My previous post was Star Programming 3

static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = num; i > 0; i--)
    {
        for (int j = 0; j < i; j++)
        {
            Console.Write("*");
        }
        Console.WriteLine();
    }
}

Friday, 29 July 2016

Star Programming 3

Introduction


Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.

My previous post was Star Programming 2

static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = num; i>0; i--)
    {
        for (int k = num - i; k > 0; k--)
        {
            Console.Write(" ");
        }
        for (int j = 2*i-1; j>0; j--)
        {
            Console.Write("*");
        }
        Console.WriteLine();
    }
}

Thursday, 28 July 2016

Star Programming 2

Introduction

Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews.


Previously I had posted   Star Programming 1        


static void Main(string[] args)
{
    Console.WriteLine("Please Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < num; i++)
    {
        for (int k = 0; k < num - i-1; k++)
        {
            Console.Write(" ");
        }
        for (int j = 0; j <2 * i + 1; j++)
        {
            Console.Write("*");
        }
        Console.WriteLine();
    }
}

Star Programming 1

Introduction


Hi guys, today I will post how to write a basic star programming in C#, this is generally helpful to the fresher and whoever preparing for interviews. Slowly I will post more Star Programming related articles.

*
**
***
****
*****
******
*******
********

static void Main(string[] args)
{
    Console.WriteLine("Enter a number");
    int num = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < num; i++)
    {
       for (int j = 0; j <= i; j++)
       {
           Console.Write("*");
       }
       Console.WriteLine();
    }
}

Wednesday, 14 October 2015

Project Euler #2: Even Fibonacci numbers

Hi folks, today I will show you how to solve Project Euler Problem 2.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1,2,3,5,8,13,21,34,55,89,
By considering the terms in the Fibonacci sequence whose values do not exceed N, find the sum of the even-valued terms.
Solution

int i = Convert.ToInt32(Console.ReadLine());
List<decimal> list = new List<decimal>();
for (int j = 0; j < i; j++)
{
   list.Add(Convert.ToInt64(Console.ReadLine()));
}
foreach (decimal k in list)
{
   long b = 1;
   long c = 2, d;
   long sum = 0;
   while (c < k)
   {
      sum += c;
      d = b + (c << 0x01);
      c = d + b + c;
      b = d;
   }
   Console.WriteLine(sum);
}

Project Euler #1: Multiples of 3 and 5

Hi guys, today I will show you how to solve Project Euler Problem 1, the question is
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000000000.

I tried to solve this question using for loop. It was working fine but it was taking so many times to get the result. Then I implemented some mathematical logic to solve this issue.


static void Main(String[] args) {
            int i = Convert.ToInt32(Console.ReadLine());
            List<long> list = new List<long>();
            for (int j = 0; j < i; j++)
            {
                list.Add(Convert.ToInt64(Console.ReadLine()));
            }
            foreach(long k in list)
            {
                long sum=0;
                long i3 = (((k - 1) / 3) * (((k - 1) / 3) + 1)) / 2;
                sum += i3 * 3;
                long i5 = (((k - 1) / 5) * (((k - 1) / 5) + 1)) / 2;
                sum += i5 * 5;
                long i15 = (((k - 1) / 15) * (((k - 1) / 15) + 1)) / 2;
                sum -= i15 * 15;
                Console.WriteLine(sum);
            }
    }