1 / 27

C# Code Exercise

C# Code Exercise. Suphot Sawattiwong tohpus@gmail.com. Ex1. int a = 9, b = 4; int t = 0; Console .WriteLine(a + "," + b); t = a; a = b; b = t; Console .WriteLine(a + "," +b); Console .ReadLine ();. Ex1_1. int a = 9, b = 4; Console .WriteLine(a + "," + b); a = a^b;

easter
Télécharger la présentation

C# Code Exercise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# Code Exercise SuphotSawattiwong tohpus@gmail.com

  2. Ex1 int a = 9, b = 4; int t = 0; Console.WriteLine(a +"," + b); t = a; a = b; b = t; Console.WriteLine(a+","+b); Console.ReadLine();

  3. Ex1_1 int a = 9, b = 4; Console.WriteLine(a +"," + b); a = a^b; b= a^b; a= a^b; Console.WriteLine(a+","+b); Console.ReadLine();

  4. Ex1_2 int a = 9, b = 4; Console.WriteLine(a +"," + b); a=a*b; b=a/b; a=a/b; Console.WriteLine(a+","+b); Console.ReadLine();

  5. Ex1_3 int a = 9, b = 4; Console.WriteLine(a +"," + b); a = a - b; b = a + b; a = b - a; Console.WriteLine(a+","+b); Console.ReadLine();

  6. Ex2 int a = 4, b=8; int max=0, min= 0; if(a<b){ max=b; min = a; }else{ max = a; min = b; } Console.WriteLine(max+">"+ min); Console.ReadLine();

  7. Ex3 int c = 0; while (c < 10) { Console.WriteLine(c); c++; } Console.ReadLine();

  8. Ex4 int c = 0; while (c < 10) { Console.WriteLine(c++); } Console.ReadLine();

  9. Ex5 int c = 0; while (c < 10) { Console.WriteLine(++c); } Console.ReadLine();

  10. Ex6 int sum = 0; int i = 0; while (i < 10) { sum += i; if (i != 0) { Console.Write("+"); } Console.Write(i); i++; } Console.WriteLine(); Console.WriteLine("Sum ={0}", sum); Console.ReadLine();

  11. Ex7 int s = 0; int i = 0; while (i < 10) { s += i; if (i != 0) { Console.Write("+"); } Console.Write(i); i=i+2; } Console.WriteLine(); Console.WriteLine("s ={0}", s); Console.ReadLine();

  12. Ex8 for(int i=0; i<5; i++){ if(i%2==0) Console.Write(i); else Console.Write(" "); } Console.ReadLine();

  13. Ex9 int a = 5,f = 1; Console.Write("{0}!=", a); for (; a > 0; a--) { f = f * a; Console.Write(a); if (a != 1) Console.Write("*"); } Console.WriteLine("={0}",f); Console.ReadLine();

  14. Ex10 int i = 1234567; while (i > 0) { Console.WriteLine(i % 10); i = i / 10; } Console.ReadLine();

  15. Ex11 int i=1234567; string s=""; while(i>0){ s= ""+(i%10)+" "+ s; i=i/10; } Console.WriteLine(s); Console.ReadLine();

  16. Ex12 int a = 4, b = 5, c = 7; int min = 0; if (a < b) min = a; if (min > c) min = c; Console.WriteLine(min); Console.ReadLine();

  17. Ex13 int a = 2,b = 5,c=1; while (a <= b){ Console.Write(" "+a+" "); a++; } Console.WriteLine();

  18. Ex13(ต่อ) do { a = 2; do { Console.Write("{0,2}*{1,2}={2,2} ", a, c, (a * c)); a++; }while (a <= b); Console.WriteLine(); c++; } while (c <= 12); Console.ReadLine();

  19. Ex14 int i = 1024; int c = 0; while (i>0) { Console.WriteLine("i=" + i); i = i >> 1; c++; } Console.WriteLine("c=" + c); Console.ReadLine();

  20. Ex15 char a ='A'; Console.WriteLine((char)(a + 32)); Console.ReadLine();

  21. Ex16 char a ='A'; for(int i=0;i<26;i++){Console.WriteLine(a++); } Console.ReadLine();

  22. Ex17 char a ='0'; int b = a; Console.WriteLine(b-48);Console.ReadLine();

  23. Ex18 int a = 3; switch (a) { case 1: Console.Write("Hello"); break; case 2: Console.Write(" ^_^ \n"); break; case 3: case 4: case 5: Console.Write(" (\",) \n\n"); Console.Write(" (@ _ @) "); break; default: Console.Write(" Default "); break; } Console.ReadLine();

  24. Ex19 string s ="Hello"; int offset = (80 - s.Length)>>1; for (int i = 0; i < offset; i++) Console.Write(" "); Console.WriteLine(s); Console.ReadLine();

  25. Ex19_1 string s ="Hello"; int offset = (80 - s.Length)/2; for (int i = 0; i < offset; i++) Console.Write(" "); Console.WriteLine(s); Console.ReadLine();

  26. Ex19_2 string s ="Hello"; int offset = (80 - s.Length); for (int i = 0; i < offset; i++) Console.Write(" "); Console.WriteLine(s); Console.ReadLine();

  27. Ex20 int a = 1; int b = 1; for (int i = 0; i < 5; i++) { if (i != 0) { b = b * 10; a = a + b; } strings ="" + (a * a); int c=(80-s.Length)/2; for (int j = 0; j < c; j++) Console.Write(" "); Console.WriteLine(s); } Console.ReadLine();

More Related