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 = string.Empty;
- int sumPrime = 0;
- int sumNonPrime = 0;
- int commandToInt = 0;
- int ifPrime = 0;
- while (command != "stop")
- {
- command = Console.ReadLine();
- if (command == "stop")
- {
- Console.WriteLine($"Sum of all prime numbers is: {sumPrime}");
- Console.WriteLine($"Sum of all non prime numbers is: {sumNonPrime}");
- }
- else
- {
- commandToInt = int.Parse(command);
- if (commandToInt < 0)
- {
- Console.WriteLine("Number is negative.");
- }
- else
- {
- for (int i = 1; i <= commandToInt; i++)
- {
- if (commandToInt % i == 0)
- {
- ifPrime++;
- }
- }
- if (ifPrime == 2)
- {
- sumPrime = sumPrime + commandToInt;
- }
- else
- {
- sumNonPrime = sumNonPrime + commandToInt;
- }
- ifPrime = 0;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement