Advertisement
walec91

Ćwiczenia #4

Dec 4th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp18
  3. {
  4.     internal class Program
  5.     {
  6.         private static void Main(string[] args)
  7.         {
  8.             #region #1
  9.             for (int i1 = 0; i1 <= 10; i1++)
  10.             {
  11.                 for (int i2 = 0; i2 <= 5; i2++)
  12.                 {
  13.                     for (int i5 = 0; i5 <= 2; i5++)
  14.                     {
  15.                         if (i1 + 2 * i2 + 5 * i5 == 10)
  16.                         {
  17.                             Console.WriteLine("jedynek = {0}\t dwójek = {1}\t piątek {2}", i1, i2, i5);
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.             Console.ReadKey();
  23.             #endregion
  24.             #region #2
  25.             for (int x = 0; x <= 1000; x++)
  26.             {
  27.                 for (int y = 0; y <= 500; y++)
  28.                 {
  29.                     for (int z = 0; z <= 200; z++)
  30.                     {
  31.                         if (x + 2 * y + 5 * z == 1000 && x == y && y == z && z == x)
  32.                         {
  33.                             Console.WriteLine("jedynek = {0}\t dwójek = {1}\t piątek {2}", x, y, z);
  34.                         }
  35.                     }
  36.                 }
  37.             }
  38.             Console.ReadKey();
  39.             #endregion
  40.             #region #3
  41.             int suma = 0;
  42.             for (int n = 1; n <= 10000; n++)
  43.             {
  44.                 suma = 0;
  45.                 for (int i = 1; i < n; i++)
  46.                 {
  47.                     if (n % i == 0)
  48.                     {
  49.                         suma += i;
  50.                     }
  51.                 }
  52.                 if (suma == n)
  53.                 {
  54.                     Console.WriteLine(n + " jest liczbą doskonałą");
  55.                 }
  56.             }
  57.             Console.ReadKey();
  58.             #endregion
  59.             #region #4
  60.             int i;
  61.             Console.WriteLine("Podaj liczbę");
  62.             int n = int.Parse(Console.ReadLine());
  63.             for (i = 2; i < n; i++)
  64.             {
  65.                 if (n % i == 0)
  66.                 {
  67.                     break;
  68.                 }
  69.  
  70.             }
  71.             if (i == n)
  72.             {
  73.                 Console.WriteLine(n + " jest liczbą pierwszą");
  74.             }
  75.             else
  76.             {
  77.                 Console.WriteLine(n + " nie jest liczbą pierwszą");
  78.             }
  79.             Console.ReadKey();
  80.             #endregion
  81. #region #5
  82.             bool czyWagaNorma;
  83.             double waga, wzrost, BMI;
  84.  
  85.             Console.Write("Podadaj wagę (w kg): ");
  86.             waga = double.Parse(Console.ReadLine());
  87.             Console.Write("Podadaj wzrost (w metrach): ");
  88.             wzrost = double.Parse(Console.ReadLine());
  89.  
  90.             BMI = waga / Math.Pow(wzrost, 2.0);
  91.             czyWagaNorma = BMI >= 18.5 && BMI < 25;
  92.             Console.WriteLine("BMI = {0}", BMI);
  93.             Console.WriteLine("Czy Twoja waga jest w normie - {0}", czyWagaNorma);
  94.  
  95.             Console.ReadKey();
  96.             #endregion
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement