Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _06.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 checkPrime = true;
- if (number < 0)
- {
- Console.WriteLine("Number is negative.");
- command = Console.ReadLine();
- continue;
- }
- if (number == 1)
- {
- primeSum+=number;
- command = Console.ReadLine();
- continue;
- }
- for (int i = 2; i <= 9; i++)
- {
- if (number % i == 0 && number !=i)
- {
- nonprimeSum+=number;
- checkPrime = false;
- break;
- }
- }
- if (checkPrime == true)
- {
- primeSum += 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