CSharp Programim ne Shqip
//1.Hyrje ne C# using System; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Pershendetje"); } } } //2. Write & WriteLine Console.WriteLine("Pershendetje!"); Console.WriteLine("Ky rrjeshti do dali tek rrjeshti 2."); Console.Write("Pershendetje! "); Console.Write("Ky rrjeshti do dali ne te njejtin rrjesht me lart."); //Tipet e te dhenave int nr = 5; double nrd = 5.99; char shkronja = 'D'; bool ss = true; string ckemi = "si kalove"; //Deklarimi Variablave string emri = "Said"; Console.WriteLine(emri); //int int numri = 15; Console.WriteLine(numri); //shembull tjeter me int int nr = 15; nr = 20; // nr merr vleren 20 Console.WriteLine(nr); //Marrja nr nga tastiera // Vendos emrin Console.WriteLine("Shkruaj emrin:"); // stringu qe do marri vleren nga tastiera string emrijuaj = Console.ReadLine(); // printo emrin qe u shkruajt nga tastiera Console.WriteLine("Emri eshte: " + emrijuaj); //Operatoret int Shum1 = 100 + 50; // 150 (100 + 50) int Shum2 = Shum1 + 250; // 400 (150 + 250) int Shum3 = Shum2 + Shum2; // 800 (400 + 400) //Funx matematike Math.Max(5, 10); Math.Min(5, 10); Math.Sqrt(64); Math.Abs(-4.7); Math.Round(9.99); //Ushtrimi 1: Console.WriteLine("11. Shkruaj moshen dhe afishoje pas 10 vitesh."); Console.WriteLine("Ju lutem jepni moshen aktuale!"); int mosha = int.Parse(Console.ReadLine()); Console.Write("Mosha juaj pas 10 vitesh do te jete: "); Console.Write(mosha + 10); //nuk lejon mbylljen e consoles pa shtypur enter Console.ReadLine(); //Kushti if-else using System; public class shembulliIF { public static void Main(string[] args) { int numri = 10; if (numri % 2 == 0) { Console.WriteLine("Nr eshte cift"); } } } //Shembulli 2 using System; public class shembulliIF { public static void Main(string[] args) { int numri = 11; if (numri % 2 == 0) { Console.WriteLine("Nr eshte cift"); } else { Console.WriteLine("Nr eshte tek"); } } }
using System; namespace Loop { class WhileLoop { public static void Main(string[] args) { int i=1; while (i<=5) { Console.WriteLine("C# iteracioni loop {0}", i); i++; } } } } //Ushtrimi 2:shuma e tyre using System; namespace Loop { class WhileLoop { public static void Main(string[] args) { int i=1, sum=0; while (i<=5) { sum += i; i++; } Console.WriteLine("Shuma = {0}", sum); } } } //3 tabela e shumezimit using System; namespace Loop { class DoWhileLoop { public static void Main(string[] args) { int i = 1, n = 5, product; do { product = n * i; Console.WriteLine("{0} * {1} = {2}", n, i, product); i++; } while (i <= 10); } } }
//Switch Case //Shembulli 1 int x = 10; switch (x) { case 5: Console.WriteLine("vlera e x= 5"); break; case 10: Console.WriteLine("vlera e x= 10"); break; case 15: Console.WriteLine("vlera e x= 15"); break; default: Console.WriteLine("Nuk dihet vlera"); break; } //Shembulli 2 int day = 4; switch (day) { case 1: Console.WriteLine("Hene"); break; case 2: Console.WriteLine("Marte"); break; case 3: Console.WriteLine("Merkure"); break; case 4: Console.WriteLine("Enjte"); break; case 5: Console.WriteLine("Premte"); break; case 6: Console.WriteLine("Shtune"); break; case 7: Console.WriteLine("Diel"); break; default: Console.WriteLine("Gabim"); break; } //Ushtrim klase: Beni sistemin e notave me switch case //Gjej zanoret dhe bashketingelloret using System; namespace Conditional { class SwitchCase { public static void Main(string[] args) { char ch; Console.WriteLine("Vendos nje shkronje"); ch = Convert.ToChar(Console.ReadLine()); switch(Char.ToLower(ch)) { case 'a': Console.WriteLine("zanore"); break; case 'e': Console.WriteLine("zanore"); break; case 'i': Console.WriteLine("zanore"); break; case 'o': Console.WriteLine("zanore"); break; case 'u': Console.WriteLine("zanore"); break; default: Console.WriteLine("Bashketingellore"); break; } } } } //Menyra dyte per zanoret using System; namespace Conditional { class SwitchCase { public static void Main(string[] args) { char ch; Console.WriteLine("Vendos nje shkronje"); ch = Convert.ToChar(Console.ReadLine()); switch(Char.ToLower(ch)) { case 'a': case 'e': case 'i': case 'o': case 'u': Console.WriteLine("Zanore"); break; default: Console.WriteLine("Bashketingellore"); break; } } } } //Makina llogaritese using System; namespace Conditional { class SwitchCase { public static void Main(string[] args) { char op; double nr1, nr2, rezultati; Console.Write("Vendos nr e pare: "); nr1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Vendos nr e dyte: "); nr2 = Convert.ToDouble(Console.ReadLine()); Console.Write("Zgjidh operatorin (+, -, *, /): "); op = (char)Console.Read(); switch(op) { case '+': rezultati = nr1 + nr2; Console.WriteLine("{0} + {1} = {2}", nr1, nr2, rezultati); break; case '-': rezultati = nr1 - nr2; Console.WriteLine("{0} - {1} = {2}", nr1, nr2, rezultati); break; case '*': rezultati = nr1 * nr2; Console.WriteLine("{0} * {1} = {2}", nr1, nr2, rezultati); break; case '/': rezultati = nr1 / nr2; Console.WriteLine("{0} / {1} = {2}", nr1, nr2, rezultati); break; default: Console.WriteLine("Gabim operatori"); break; } } } }
//Shfaq nr nga 1 ne 10 for(int i = 1; i < 10; i++) { Console.WriteLine("Nr: {0}", i); } //Shfaq nr nga 10 ne 1 for(int i = 10; i > 1; i--) { Console.WriteLine("Nr: {0}", i); } //perjashto 4 nga nr 1-10 for (int i = 1; i < 10; i++) { if( i == 4 ) break; Console.WriteLine("Nr: {0}", i); } //shuma e 10 nr int n = 5,shuma = 0; for (int i=1; i<=n; i++) { // shuma = shuma + i; shuma += i; } Console.WriteLine("Shuma e {0} numrave eshte = {1}", n, shuma); //Detyre: Shfaq 4 here fjalen Impact for (int ____; x ____; x____) Console.WriteLine("____"); } //Shfaq 10 nr e pare tek dhe mblidhi me njeri tjetrin int i,n,shuma=0; Console.Write("Vendos nr : "); n= Convert.ToInt32(Console.ReadLine()); Console.Write("\nNr tek jane :"); for(i=1;i<=n;i++) { Console.Write("{0} ",2*i-1);//2 *i-1 dmth sa here gjen nr cift i zbret 1 e ben tek shuma=shuma+2*i-1; } Console.Write("\nShuma e nr tek {0} eshte : {1} \n",n,shuma); //Detyre : bej te njejtin ushtrim si me siper por me if-else dhe for if(nr%2 == 0){ Console.WriteLine("Tek") }
//Deklarimet dhe inicializimet int[] cift = new int[5]{ 2, 4, 6, 8, 10 }; string[] qytete = new string[3]{ "Tirane", "London", "New York" }; //Menyra dyte e deklarimit int[] cift = { 2, 4, 6, 8, 10}; string[] qytete = { "Tirane", "London", "New York" } //printo elementet sipas index int[] cift = new int[5]; cift[0] = 2; cift[1] = 4; //cift[6] = 12; //jep gabim Console.WriteLine(cift[0]); //printon 2 Console.WriteLine(cift[1]); //printon 4 //shfaq numrat int[] cift = { 2, 4, 6, 8, 10 }; for(int i = 0; i < cift.Length; i++) Console.WriteLine(cift[i]); for(int i = 0; i < cift.Length; i++) cift[i] = cift[i] + 10;//shto rezultatin +10 //hidh dhe shfaq notat e nje studenti int[] nota = new int[10]; int i; int j; int num=80; for(i=0; i<10; i++) { nota[i] = num; num++; } for(j=0; j<10; j++) { Console.WriteLine("nota[{0}] = {1}", j, nota[j]); } Console.ReadKey(); //Hedhja e notave te studentit string[] studentId = { "STU01", "STU02", "STU03", "STU04", "STU05" }; int[] notat = { 76, 83, 92, 65, 34 }; Console.WriteLine("Gjej noten per cdo student"); for(int i=0;i<studentId.Length;i++) { if (notat[i] > 90) { Console.WriteLine(studentId[i] + " NOTA JUAJ:: " + "A"); }else if(notat[i] > 80) { Console.WriteLine(studentId[i] + " NOTA JUAJ:: " + "B"); } else if (notat[i] > 70) { Console.WriteLine(studentId[i] + " NOTA JUAJ:: " + "C"); } else if (notat[i] > 50) { Console.WriteLine(studentId[i] + " NOTA JUAJ:: " + "D"); } else { Console.WriteLine(studentId[i] + " NOTA JUAJ:: " + "FAIL"); } } Console.ReadKey();