Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SumPrimeNonPrime
- {
- class Program
- {
- static void Main(string[] args)
- {
- double prime = 0;
- double nonPrime = 0;
- string num = Console.ReadLine();
- while (num != "stop")
- {
- double number = double.Parse(num);
- if (number >= 0)
- {
- if (number % 2 == 0 || number % 3 == 0 || number % 5 == 0)
- {
- if (number == 2 || number == 3 || number == 5 || number == 7)
- {
- prime += number;
- }
- else
- {
- nonPrime += number;
- }
- }
- else
- {
- prime += number;
- }
- }
- else
- {
- Console.WriteLine("Number is negative.");
- }
- num = Console.ReadLine();
- }
- Console.WriteLine($"Sum of all prime numbers is: {prime}");
- Console.WriteLine($"Sum of all non prime numbers is: {nonPrime}");
- }
- }
- }
Add Comment
Please, Sign In to add comment