Print Friendly and PDF
(Table of Powers Application) Write an application that displays a table of numbers from 1 to an upper limit, along with each number’s squared value (for example, the number n to the power 2, or n ^ 2) and cubed value (the number n to the power 3, or n ^ 3). The users should specify the upper limit, and the results should be displayed in a ListBox,
(Table of Powers Application) Write an application that displays a table of numbers from 1 to an upper limit, along with each number’s square value  (for example, the number n to the power 2, or n ^ 2) and cubed value (the number n to the power 3, or n ^ 3). The users should specify the upper limit, and the results should be displayed in a ListBox, as  shown below 

Table of Powers Application in C#

Solution

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Table_of_Powers_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            int intLimit = 0; 
            int intCounter = 1;

            lstResults.Items.Clear();
            intLimit = Int32.Parse(txtInput.Text);
            lstResults.Items.Add("N\tN^2\tN^3");
            
            while (intCounter <= intLimit)
            {
                lstResults.Items.Add(intCounter + "\t" +
                Math.Pow(intCounter, 2) + "\t" +
                Math.Pow(intCounter, 3));
                intCounter++;
            }
        }

        private void txtInput_Click(object sender, EventArgs e)
        {
            lstResults.Items.Clear();
        }
    }
    }
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: