Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace ConsoleApp14
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- #region silnia
- //int silnia = 1;
- //Console.Write("Podaj n: ");
- //int n = int.Parse(Console.ReadLine());
- //for (int i = 1; i <= n; i++)
- //{
- // silnia *= i;
- // Console.WriteLine("Silnia ({0}) = {1}", i, silnia);
- //}
- //Console.ReadKey();
- #endregion
- #region S(n)
- //int suma = 0, i;
- //Console.Write("Podaj n: ");
- //int n = int.Parse(Console.ReadLine());
- //for (i = 1; i <= n; i++)
- //{
- // if (i % 2 == 0)
- // {
- // suma -= i;
- // }
- // else
- // {
- // suma += i;
- // }
- //}
- //Console.WriteLine("Suma ({0}) = {1}", n, suma);
- //Console.ReadKey();
- #endregion
- #region S(n).1
- //int suma = 0, i, składnik, mnożnik = 1;
- //Console.Write("Podaj n: ");
- //int n = int.Parse(Console.ReadLine());
- //for (i = 1; i <= n; i++)
- //{
- // składnik = mnożnik * i;
- // suma += składnik;
- // mnożnik -= mnożnik;
- //}
- //Console.WriteLine("Suma ({0}) = {1}", n, suma);
- //Console.ReadKey();
- #endregion
- #region tablica #1
- //int suma = 0;
- //int[] a = new int[4];
- //a[0] = 1;
- //a[1] = 3;
- //a[2] = 8;
- //a[3] = 5;
- //for (int i = 0; i < 4; i++)
- //{
- // suma += a[i];
- //}
- //Console.WriteLine("Suma wszytskich wyrazów wynosi: {0}", suma);
- //Console.ReadKey();
- #endregion
- #region tablica #2
- //int suma = 0,n;
- //Console.Write("Podaj długość tablicy: ");
- //n = int.Parse(Console.ReadLine());
- //int[] a = new int[n];
- //for (int i = 0; i < n; i++)
- //{
- // Console.Write("Podaj a[{0}]: ", i);
- // a[i] = int.Parse(Console.ReadLine());
- //}
- //for (int i = 0; i < n; i++)
- //{
- // suma += a[i];
- //}
- //Console.WriteLine("Suma wszytskich wyrazów wynosi: {0}", suma);
- //Console.ReadKey();
- #endregion
- #region Random #1
- //int suma = 0, n;
- //Console.Write("Podaj długość tablicy: ");
- //n = int.Parse(Console.ReadLine());
- //int[] a = new int[n];
- //Random r = new Random();
- //for (int i = 0; i < n; i++)
- //{
- // a[i] = r.Next(-5, 11);
- // Console.WriteLine("a[{0}] = {1}", i, a[i]);
- //}
- //foreach (int x in a)
- //{
- // suma += x;
- //}
- //Console.WriteLine("Suma wszytskich wyrazów wynosi: {0}", suma);
- //Console.ReadKey();
- #endregion
- #region Random #2
- int n, sumaDodatnich = 0, sumaUjemnych = 0;
- Console.Write("Podaj długość tablicy: ");
- n = int.Parse(Console.ReadLine());
- int[] a = new int[n];
- Random r = new Random();
- for (int i = 0; i < n; i++)
- {
- a[i] = r.Next(-5, 11);
- Console.WriteLine("a[{0}] = {1}", i, a[i]);
- }
- foreach (int x in a)
- {
- if (x > 0)
- {
- sumaDodatnich += x;
- }
- else
- {
- sumaUjemnych += x;
- }
- }
- Console.WriteLine("Suma liczb dodatnich wynosi: {0}", sumaDodatnich);
- Console.WriteLine("Suma liczb ujemnych wynosi: {0}", sumaUjemnych);
- Console.ReadKey();
- #endregion
- #region Random #3
- int n, sumaDodatnich = 0, sumaUjemnych = 0, suma = 0, ld = 0, lu = 0, lz = 0;
- Console.Write("Podaj długość tablicy: ");
- n = int.Parse(Console.ReadLine());
- int[] a = new int[n];
- Random r = new Random();
- for (int i = 0; i < n; i++)
- {
- a[i] = r.Next(-5, 6);
- Console.WriteLine("a[{0}] = {1}", i, a[i]);
- }
- for (int i = 0; i < n; i++)
- {
- suma += a[i];
- }
- Console.WriteLine("Suma = " + suma);
- foreach (int x in a)
- {
- if (x > 0)
- {
- sumaDodatnich += x;
- ld++;
- }
- else if (x < 0)
- {
- sumaUjemnych += x;
- lu++;
- }
- else
- {
- lz++;
- }
- }
- Console.WriteLine("Suma liczb dodatnich wynosi: {0}, a jest ich {1}", sumaDodatnich, ld);
- Console.WriteLine("Suma liczb ujemnych wynosi: {0}, a jest ich {1}", sumaUjemnych, lu);
- Console.WriteLine("Liczba zer wynosi {0}", lz);
- Console.ReadKey();
- #endregion
- #region Lotto
- int[] t = new int[6];
- Random r = new Random();
- int i = 0;
- while (i < 6)
- {
- t[i] = r.Next(1, 50);
- int popr = 1;
- for (int j = 0; j < i; j++)
- {
- if (t[i] == t[j])
- {
- popr = 0;
- }
- }
- if (popr == 1)
- {
- i++;
- }
- }
- for (int k = 0; k < 6; k++)
- {
- Console.Write(t[k] + " ");
- }
- Console.ReadKey();
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement