Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static int sumowanie(int[] tab, int p, int k)
- {
- int suma = 0;
- do
- {
- int i = p;
- suma += tab[i];
- p++;
- } while (p <= k);
- return suma;
- }
- static void Main(string[] args)
- {
- int[] tab = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- Console.WriteLine("Ilosc elementow w tablicy: " + tab.Length.ToString());
- Console.WriteLine("Podaj element poczatkowy tablicy");
- int p = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Podaj element koncowy tablicy");
- int k = Convert.ToInt32(Console.ReadLine());
- if(p<0 || p > tab.Length) {
- Console.WriteLine("Blad w wyborze elementów początkowego i końcowego. Wybierz elementy od 0 do " + tab.Length.ToString());
- } else
- {
- Console.Write("Suma elementow tablicy od " + p.ToString() + " do " + k.ToString());
- Console.WriteLine();
- Console.WriteLine("Suma: "+sumowanie(tab, p, k).ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement