C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, 24 November 2014

Recurrence of numbers in an array

Write a program that finds in a given array of integers (in the range
[0…1000]) how many times each of them occurs.
Example: array = {3, 4, 4, 2, 3, 3, 4, 3, 2}Chapter 16. Linear Data Structures 677
2  2 times
3  4 times

4  3 times


using System;
using System.Linq;

namespace ConsoleApplication8
{

    class Program
    {
        
        static void Main()
        {

            int[] source = new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 6, 7 };

            foreach (var item in source.Distinct())
            {
                
                Console.WriteLine("{0} => {1} Times",item,source.Count(f => f == item));  
            }
            Console.ReadLine();
        }
    }
}



Sunday, 23 November 2014

Write a program that reads from the console a positive integer number N (N < 20) and prints a matrix of numbers as on the figures below:

Write a program that reads from the console a positive integer number
N (N < 20) and prints a matrix of numbers as on the figures below:


N = 3 
1 2 3
2 3 4
3 4 5

N = 4
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7


using System;

namespace ConsoleApplication8
{

    class Program
    {

        static void Main()
        {

            for (int i = 1; i <= 3; i++)
            {
                for (int j = 0; j <=2; j++)
                {
                    Console.Write(i+j);
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}






Friday, 21 November 2014

Create An Array with Non Default Value

namespace ConsoleApplication8
{

    class Program
    {
        static void Main(string[] args)
        {

            int[] intArray = Enumerable.Repeat(100, 5).ToArray();

            foreach (var x in intArray)
            {
                Console.WriteLine(x);
            }
            Console.ReadLine();
        }
    }
}