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