Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SumPrimeNonPrime
- {
- class Program
- {
- static void Main(string[] args)
- {
- string command = Console.ReadLine();
- int primeSum = 0;
- int nonPrimeSum = 0;
- while (command != "stop")
- {
- int number = int.Parse(command);
- bool isPrime = true;
- if (number < 0)
- {
- Console.WriteLine("Number is negative.");
- command = Console.ReadLine();
- continue;
- }
- if (number == 1)
- {
- isPrime = false;
- }
- else
- {
- for (int i = number; i >= 2; i--)
- {
- if (number % i == 0 && i != number)
- {
- isPrime = false;
- break;
- }
- }
- }
- if (isPrime)
- {
- primeSum += number;
- }
- else
- {
- nonPrimeSum += number;
- }
- 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