Question

In: Computer Science

In C# Please Write an application named Perfect that displays every perfect number from 1 through...

In C# Please Write an application named Perfect that displays every perfect number from 1 through 10,000. A number is perfect if it equals the sum of all the smaller positive integers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it and their sum is 6.

Starting code.


using static System.Console;
class Perfect
{
static void Main()
{
// Write your main here.
}
}

Solutions

Expert Solution

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Perfect
{
class Program
{
static void Main(string[] args)
{
int n, i, sum;
int mn, mx;

Console.Write("\n\n");
Console.Write("Find perfect numbers within a given number of range:\n");
Console.Write("------------------------------------------------------");
Console.Write("\n\n");

Console.Write("Starting number : ");
mn = Convert.ToInt32(Console.ReadLine());
Console.Write("Ending number : ");
mx = Convert.ToInt32(Console.ReadLine());
Console.Write("The Perfect numbers in range : ");
for (n = mn; n <= mx; n++)
{
i = 1;
sum = 0;
while (i < n)
{
if (n % i == 0)
sum = sum + i;
i++;
}
if (sum == n)
Console.Write("{0} ", n);
}
Console.Write("\n");
Console.ReadLine();
}   
}
}


if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)


Related Solutions

Write an application named DisplayMultiplicationTable that displays a table of the products of every combination of...
Write an application named DisplayMultiplicationTable that displays a table of the products of every combination of two integers from 1 through 10 Beginning Code. Please answer in C# using static System.Console; class DisplayMultiplicationTable { static void Main() { // Write your main here. } } }
Write an application named OddNums that displays all the odd numbers from 1 through 99. All...
Write an application named OddNums that displays all the odd numbers from 1 through 99. All ODD numbers should show all together(Should not need to scroll down), do it in 10 rows. FOR C#
Java Write a JavaFX application that displays a button and a number. Every time the button...
Java Write a JavaFX application that displays a button and a number. Every time the button is pushed, change the number to a random value between 1 and 100. Thank you and can you show a picture of the result as well
#1 Write a loop that displays every fifth number, 0 through 100. #2 Write a do-...
#1 Write a loop that displays every fifth number, 0 through 100. #2 Write a do- while loop that asks the user to enter two numbers. The number should be added and the sum displayed. The user should be asked if he or she wishes to perform the operation again. if so, the loop should repeat; otherwise it should terminate. #3 Write a nested loop that displays 10 rows of '#' characters. There should be 15 '#' characters in each...
Write a program named MakeChange that calculates and displays the conversion of an entered number of...
Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones. For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3. Answer in C# (P.S i'm posting the incomplete code that i have so far below.) using System; using static System.Console; class MakeChange { static void Main() { int twenties, tens, fives, ones; WriteLine("Enter the number of dollars:");...
Write a Java application that inputs an unknown number of employees and determines and displays the...
Write a Java application that inputs an unknown number of employees and determines and displays the gross pay for each employ. The company pays straight time for the first 40 hours worked by each employee (hours times rate), and straight time plus time-and-a-half for all hours worked in excess of 40 hours. Input the number of hours worked and hourly rate for each of the employees, then determine and display the employee’s gross pay. At the end of the program,...
In C# Create a windows application which accepts the month number and displays the month name...
In C# Create a windows application which accepts the month number and displays the month name in a label.   Use a nested if... else statement to determine the month name. For months not in the range 1-12 display the message "Not a valid month"
*Code in C* Write a function that checks if a number is a perfect cube. Write...
*Code in C* Write a function that checks if a number is a perfect cube. Write another function that calculates the integer cubic root. Under the main program: Prompt the user to input a number Tell the user if the number is a perfect cube or not Print the cubic root if the inputted number is a perfect cube.
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:         ● Subtotal using a cost of $3.50 per yogurt.         ● Subtotal...
(Language: c++)Write a program that displays a question and 4 possible answers numbered 1 through 4....
(Language: c++)Write a program that displays a question and 4 possible answers numbered 1 through 4. . The program should ask the user to answer 1, 2, 3, or 4 and tell them if they are correct or not. If the user enters anything besides 1, 2, 3, or 4 the program should return an error message example outout: whats 2+5? 1. 4 2. 7 3. 1 4. 0 // if user inputs anything other then option 2 the screen...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT