Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Toistorakennetehtava
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int luku;
  15.  
  16. Console.WriteLine("Anna valintasi: ");
  17. int.TryParse(Console.ReadLine(), out luku);
  18.  
  19. int i, n, kertoma;
  20.  
  21. while (luku == 1)
  22. {
  23.  
  24. Console.Write("Anna kokonaisluku, jonka kertoman tahdot: ");
  25. int.TryParse(Console.ReadLine(), out n);
  26.  
  27. kertoma = n;
  28. i = n - 1;
  29.  
  30. while (i > 0)
  31. {
  32. kertoma *= i;
  33. i--;
  34. }
  35. Console.WriteLine("{0}! = {1}", n, kertoma);
  36.  
  37. Console.WriteLine("Anna valintasi: ");
  38. int.TryParse(Console.ReadLine(), out luku);
  39.  
  40.  
  41. }
  42.  
  43. while (luku == 0)
  44. {
  45. Console.WriteLine("Ohjelma lopetetaan");
  46. Environment.Exit(0);
  47. }
  48.  
  49. while (luku >= 1)
  50. {
  51. Console.WriteLine("Annoit väärän valinnan!");
  52. Console.WriteLine("Anna valintasi: ");
  53. int.TryParse(Console.ReadLine(), out luku);
  54.  
  55. while (luku == 1)
  56. {
  57.  
  58. Console.Write("Anna kokonaisluku, jonka kertoman tahdot: ");
  59. int.TryParse(Console.ReadLine(), out n);
  60.  
  61. kertoma = n;
  62. i = n - 1;
  63.  
  64. while (i > 0)
  65. {
  66. kertoma *= i;
  67. i--;
  68. }
  69. Console.WriteLine("{0}! = {1}", n, kertoma);
  70.  
  71. Console.WriteLine("Anna valintasi: ");
  72. int.TryParse(Console.ReadLine(), out luku);
  73.  
  74.  
  75. }
  76.  
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement