Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace NestexExam_n6
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. string command = Console.ReadLine();
  11.  
  12. int sumOfPrime = 0;
  13. int sumOfNonPrime = 0;
  14. int min = int.MinValue;
  15. int max = int.MaxValue;
  16. while ( command != "stop")
  17. {
  18. for (int i = min; i <= max; i++)
  19. {
  20. int n = int.Parse(Console.ReadLine());
  21.  
  22. if ( n < 0)
  23. {
  24. Console.WriteLine("Number is negative.");
  25. continue;
  26. }
  27. if ( n / 1 == n || n / n == 1)
  28. {
  29. sumOfPrime += n;
  30. }
  31. else
  32. {
  33. sumOfNonPrime += n;
  34. }
  35.  
  36. }
  37.  
  38.  
  39. }
  40. Console.WriteLine($"Sum of all prime numbers is: {sumOfPrime}");
  41. Console.WriteLine($"Sum of all non prime numbers is: {sumOfNonPrime}");
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement