Q:

Write a program in C# Sharp to find the number of an array and the square of each number

0

Write a program in C# Sharp to find the number of an array and the square of each number.

Expected Output :
{ Number = 9, SqrNo = 81 }
{ Number = 8, SqrNo = 64 }
{ Number = 6, SqrNo = 36 }
{ Number = 5, SqrNo = 25 }

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
using System.Collections.Generic;
class LinqExercise3
{
 static void Main(string[] args)
    {
    // code from DevCurry.com
    var arr1 = new[] { 3, 9, 2, 8, 6, 5 };
            Console.Write("\nLINQ : Find the number and its square of an array which is more than 20 : "); 
            Console.Write("\n------------------------------------------------------------------------\n");	
    var sqNo = from int Number in arr1
                    let SqrNo = Number * Number
                    where SqrNo > 20
                    select new { Number, SqrNo };
    foreach (var a in sqNo)
        Console.WriteLine(a);
    Console.ReadLine();
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now