Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Prime_and_Non_prime
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = string.Empty;
- int primeSUM = 0;
- int nonPrimeSUM = 0;
- int num = 0;
- while (true)
- {
- input = Console.ReadLine();
- if (input == "stop")
- break;
- num = int.Parse(input);
- if (num < 0)
- Console.WriteLine("Number is negative.");
- else
- {
- int i = 2;
- while (num % i != 0) i++;
- if (i == num)
- primeSUM += num;
- else
- nonPrimeSUM += num;
- }
- }
- Console.WriteLine($"Sum of all prime numbers is: {primeSUM}");
- Console.WriteLine($"Sum of all non prime numbers is: {nonPrimeSUM}");
- }
- }
- }
Add Comment
Please, Sign In to add comment