Advertisement
neogz

C# - Niz, foreach petlja

Oct 19th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 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 sisarp
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             /*Zadatak 0:
  14.                Napravite program sljedeći navedene zahtjeve:
  15.                a) neka korisnik sa tastature vrši unos cijelog broja x
  16.                b) deklarišite niz N tipa int veličine x
  17.                c) učitajte vrijednost niza sa tastature koristeći for petlju
  18.                d) ispišite vrijednost niza koristeći foreach petlju. (Objašnjenje foreach petlje slijedi u nastavku.)*/
  19.  
  20.             int size;
  21.             Console.WriteLine("unesite velicinu niza: ");
  22.             size = int.Parse(Console.ReadLine());
  23.  
  24.             int [] n = new int[size];
  25.  
  26.             for (int i = 0; i < n.Length; i++)
  27.             {
  28.                 Console.Write("Unesite " + (i+1) + " clan: ");
  29.                 n[i] = int.Parse(Console.ReadLine());
  30.             }
  31.  
  32.             foreach (int i in n)
  33.                 Console.WriteLine(i);
  34.  
  35.          
  36.  
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement