okay I found a code that displays the prime numbers, but i need to find the average of the dispalyed prime numbers. Here is the code does anyone what to let me know how to find the average please. using System; namespace PrimeNumbers { /// /// Summary description for Class1. /// class PrimeNumbers { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // Ask the user for the quantity to check for Prime Numbers. Console.Write("Please enter the quantity to test for Prime Number: "); // Assign topNumber with User's Input. ulong topNumber = ulong.Parse(Console.ReadLine()); // Create an boolean array, numbers bool[] numbers = new bool[topNumber]; // Assign all the values in numbers with 'true'. for (ulong i = 0; i < topNumber; i++) { numbers[i] = true; } // Assign all those mutiples of 2 and 3 to be 'false'. // So that it facilitate you in finding the Prime Numbers. for (ulong i = 2; i < topNumber; i++) { if(numbers[i]) { for(ulong j = i * 2; j < topNumber; j += i) numbers[j] = false; } } // The counter to count how many Prime Numbers. ulong primes = 0; // For the remaining numbers which are still 'true' are Prime Numbers. for (ulong i = 1; i < topNumber; i++) { if(numbers[i]) { primes++; Console.Out.WriteLine(i); } } Console.Out.WriteLine(); Console.Out.WriteLine(primes + " out of " + topNumber + " prime numbers found."); Console.In.ReadLine(); } } } Ryan
diabolusgorgon
Posts
-
C# Code to find the average of prime numbers between 1-100 -
C# Code to find the average of prime numbers between 1-100:confused: Please is there any one out there that can help me I am having a very tough time trying to figure this crap out. I know I have to create a loop to find the prime numbers, but i can't figure it out. I have never done any programming before. This is my 4th week in my C# programming class and its going to fast for me. This website is supposed to have free code and tutorials. does anyone know the code for this? Please help I am lost! Ryan
-
C# code to find Prime NumbersSimplest? I don't understand this very much. Write a function that loops thru from 3 - sqrt(number) and if the mod results in 0 at any point then that number is not a prime. What??? This is really hard to understand I am only in my 4th week of programming and its moving to fast. I haven't done any programming before. Could you please help me?
-
C# code to find Prime NumbersI know I have to make a loop and check every number if it is a prime number, But I'm still lost. I'm not sure on how to set it up. I don't know what an array list is either. This is only my fourth week in my programming class and I have never done any programming before, this stuff is really hard to understand.
-
C# code to find Prime NumbersHi, I am trying to write a program that finds the average of all prime numbers between 1 and 100 and prints the average to the screen. But i can't use numbers from a predetermined prime numbers list. Can any one help me? Ryan H
-
Does anyone know a C# payroll program?I'm looking for a C# program that prompts the user for an hourly rate and the number of hours worked. It should compute the gross pay rate, withholding tax and net pay. The withholding tax is computed as a percentage of gross pay based on: Gross Pay 300 is 12% withholding Please can any one let me know if they have a C# program for this