Advertisement
andreisophie

Citire

Oct 26th, 2020
1,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. class Program
  2.     {
  3.         static int Citire()
  4.         {
  5.             int rez = 0, c;
  6.             c = Console.Read();
  7.             while (c != 32 && c != 13)
  8.             {
  9.                 rez = rez * 10 + (c - 48);
  10.                 c = Console.Read();
  11.             }
  12.             return rez;
  13.         }
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             int n = 0, k = 0, x = 0;
  18.             int[] v = new int[1000];
  19.             n = Convert.ToInt32(Console.ReadLine());
  20.  
  21.             for (int i = 1; i <= n; i++)
  22.                 v[i] = Citire();
  23.             Console.ReadLine();
  24.  
  25.             k = Convert.ToInt32(Console.ReadLine());
  26.  
  27.             x = Convert.ToInt32(Console.ReadLine());
  28.  
  29.             if (k <= n)
  30.             {
  31.                 for (int i = n; i >= k; i--)
  32.                     v[i + 1] = v[i];
  33.                 v[k] = x;
  34.                 n++;
  35.                 for (int i = 1; i <= n; i++)
  36.                     Console.Write(v[i] + " ");
  37.             }
  38.             else
  39.                 Console.WriteLine("pozitie depasita\nlungime vector=" + n);
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement