Question

Need to be solved in c# Write the program using the method that calculates the cube...

Need to be solved in c#

Write the program using the method that calculates the cube of numbers from 1 to 9 that comes as a parameter to it as a series.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Aim : To write a c# program using the method that calculates the cube of numbers from 1 to 9.

Source code :

using System;
using System.Linq;
using System.Collections.Generic;
public class CalCube {
  
    public static void cube(List<int> list){//method to find the cubes
        IEnumerable<int> res = list.AsQueryable().Select(c => c * c * c);// cube of each element
        Console.WriteLine("Cube of each element...");
        foreach (int n in res)//loop to print Cube of each element
        Console.WriteLine(n);
    }
    public static void Main() {
        CalCube d=new CalCube();
        List<int> list = new List<int> {1, 2, 3, 4, 5, 6, 7,8, 9 };
        //Console.WriteLine("Elements...");
        //foreach (int n in list) //loop to print given elements
        //Console.WriteLine(n);
        CalCube.cube(list); //invoking the cube method
    }
}

"Refer the below screenshot of the code to understand the indentation of the code"

8 Calcube.cs * 1 using System; 2 using System.Linq; 3 using System.Collections.Generic; 4 public class Calcube { 5 6 public s

Sample output :

Cube of each element... 1 8 27 64 125 216 343 512 729 Program finished with exit code 0 Press ENTER to exit console.

This is how we can write a program using the method that calculates the cube of numbers from 1 to 9 that comes as a parameter to it as a series.

Add a comment
Know the answer?
Add Answer to:
Need to be solved in c# Write the program using the method that calculates the cube...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT