Advertisement
Adijata

Prva vježba 2013 RPR treći zadatak

Oct 9th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication7
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.          
  14.             Console.WriteLine("Unesite veličinu niza: ");
  15.             int vel = int.Parse(Console.ReadLine());
  16.             int[] niz = new int[vel];
  17.  
  18.             Console.WriteLine("Unesite {0} brojeva: ", vel);
  19.             for (int i = 0; i < vel; i++)
  20.             {
  21.                 niz[i] = int.Parse(Console.ReadLine());
  22.             }
  23.             int size = niz.Length;
  24.             Program.sort(niz);
  25.             Console.WriteLine("Unesite broj koji želite izbaciti");
  26.             int br = int.Parse(Console.ReadLine());
  27.  
  28.             Program.izbaci(br,ref size, niz);
  29.  
  30.             for (int i = 0; i < size; i++)
  31.             {
  32.                 Console.WriteLine(niz[i]);
  33.             }
  34.                
  35.             Console.ReadLine();
  36.         }
  37.  
  38.         static void sort(params int[] niz)
  39.         {
  40.             for (int i = 0; i < niz.Length; i++)
  41.             {
  42.                 for (int j = i+1; j < niz.Length; j++)
  43.                 {
  44.                     if (niz[i] > niz[j])
  45.                     {
  46.                         int temp = niz[i];
  47.                         niz[i] = niz[j];
  48.                         niz[j] = temp;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.         static void izbaci(int a, ref int vel, params int[] niz)
  54.         {
  55.  
  56.             for(int i=0; i<vel; i++)
  57.             {
  58.                 if(niz[i]==a){
  59.                 for(int j=i; j<vel-1; j++)
  60.                     niz[j]=niz[j+1];
  61.                 i--;
  62.                 vel--;
  63.                 }
  64.             }
  65.  
  66.         }
  67.  
  68.  
  69.  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement