knikolov98

Untitled

Oct 15th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Prime_and_Non_prime
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = string.Empty;
  10.             int primeSUM = 0;
  11.             int nonPrimeSUM = 0;
  12.             int num = 0;
  13.  
  14.             while (true)
  15.             {
  16.                 input = Console.ReadLine();
  17.  
  18.                 if (input == "stop")
  19.                     break;
  20.  
  21.                 num = int.Parse(input);
  22.  
  23.                 if (num < 0)
  24.                     Console.WriteLine("Number is negative.");
  25.  
  26.                 else
  27.                 {
  28.                     int i = 2;
  29.  
  30.                     while (num % i != 0) i++;
  31.  
  32.                     if (i == num)
  33.                         primeSUM += num;
  34.                     else
  35.                         nonPrimeSUM += num;
  36.                 }
  37.             }
  38.  
  39.  
  40.             Console.WriteLine($"Sum of all prime numbers is: {primeSUM}");
  41.             Console.WriteLine($"Sum of all non prime numbers is: {nonPrimeSUM}");
  42.         }
  43.     }
  44.  
  45.  
  46. }
Add Comment
Please, Sign In to add comment