background image

1.
    class Program
    {
        static void Main(string[] args)
        {
            int x = Int32.Parse(Console.ReadLine());
            int i=2;
            Console.WriteLine("Rozkład liczby " + x.ToString() + " na czynniki pierwsze: ");
            while (x != 1)
            {
            "

if (x % i == 0)

              " {
             "     x = x / i;
              "     Console.WriteLine(i.ToString());
              "     i = 2;
              " }
                else
                    i++;
            }
            Console.ReadKey();
        }
    }

2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            while (x < 2)
            {
                Console.WriteLine("Podaj liczbę naturalną powyżej 1!");
                x = Convert.ToInt32(Console.ReadLine());
            }

            bool[] tablica = new bool[x + 1];
            for (int i = 2; i * i <= x; i++)
            {
                if (tablica[i] == true)
                { continue; }
                
                for (int j = 2 * i; j <= x; j += i)
                {
                    tablica[j] = true;
                }
            }
           

background image

            Console.WriteLine("Dostepne liczby pierwsze do podanej :");

            for (int y = 2; y < x + 1; y++)
            {
                if (tablica[y] == false)
                {
                    Console.Write(y + " ");
                }
            }
            Console.ReadKey();
        }
    }
}

3a.

background image

3b.

4.
            int max;
            int min;
            Console.WriteLine("Podaj długość ciągu: ");
            int n = Int32.Parse(Console.ReadLine());
            int[] tab = new int[n];
            Console.WriteLine("Podaj elementy: ");
            tab[0] = Int32.Parse(Console.ReadLine());
            max=tab[0];
            min=tab[0];
            for(int i=1; i<n; i++)
            {
                tab[i] = Int32.Parse(Console.ReadLine());
                if(tab[i]>max)
                        max=tab[i];
                if(tab[i]<min)
                        min=tab[i];
            }
            Console.WriteLine("Max = {0}, a Min = {1}", max, min);
            Console.ReadKey();

background image

5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program_5
{
    class Program
    {
        static void Main(string[] args)
        {
            int licznik = 0, n = 0, element = 0;
            Console.WriteLine("Podaj długość tablicy: ");
            n = Convert.ToInt32(Console.ReadLine());
            int[] tab = new int[n];
            
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Podaj liczbę " + i + " : ");
                tab[i] = Convert.ToInt32(Console.ReadLine());
            }
"

    

"

    for (int i = 0; i < n; i++)

"

    {

"

    "

element = tab[i];

"

"

for (int u = 0; u < n; u++)

"

"

{

"

"

"

if (tab[u] == element)

"

"

"

{ licznik++; }

"

"

}

"

"

if (licznik > (n/2))

"

"

{

"

"

"

Console.WriteLine("Jest lider !: " + element);

"

"

"

Console.ReadKey();

"

"

"

return;

"

"

}

"

"

licznik = 0;

"

    }

            Console.WriteLine("Nie ma lidera !");
"

    Console.ReadKey();

        }
    }
}

background image

6a.

// 6a.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
"

int n,k;

"

double liczba;

cout<<"podaj n"<<endl;
cin>>n;
double* tablica = new double [n];//alokacja tablicy o rozmiarze n
double* tablica2 = new double [n];
int* t_index = new int [n];
cout<<"podawaj liczby"<<endl;
for(int i=0;i<n;i++)
"

cin>>tablica[i];

for(int i=0;i<n;i++)
"

tablica2[i]=tablica[i];

for(int i=0;i<n;i++)
"

for(int j=0;j<n-1;j++)

"

"

if(tablica[j]>tablica[j+1])

"

"

{

"

"

"

liczba=tablica[j+1];

"

"

"

tablica[j+1]=tablica[j];

"

"

"

tablica [j]=liczba;

"

"

}

for(int j=0;j<n;j++)
"

for(int i=0;i<n;i++)

"

"

if(tablica2[i]==tablica[n-j-1])

"

"

"

t_index[n-j-1]=i;

cout<<"dwie ostatnie to "<<tablica[n-2]<<"("<<t_index[n-2]<<")"<<" , 
"<<tablica[n-1]<<"("<<t_index[n-1]<<")"<<endl;
cout<<"podaj k"<<endl;
cin>>k;
cout<<"pozycja k-tego elementu "<<tablica[n-k]<<"("<<t_index[n-k]<<")"<<endl;
delete [] tablica;
system("pause");
"

return 0;

}