Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 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 Zadatak1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //Napisati program koji traži točno definiran unos dvaju brojeva i neke operacije i potom obavlja tu operaciju
  14.  
  15. Console.Write("Upisite dva broja i operaciju u obliku 'broj1 +/-/*/ / broj2': ");
  16. string izraz = Console.ReadLine();
  17. int broj1 = 0;
  18. int broj2 = 0;
  19. string operacija = null;
  20. for (int i = 0; i <= izraz.Length - 1; i++)
  21. {
  22. if (izraz[i] == '+' || izraz[i] == '-' || izraz[i] == '*' || izraz[i] == '/')
  23. {
  24. broj1 = int.Parse(izraz.Substring(0, i));
  25. operacija = izraz.Substring(i, 1);
  26. broj2 = int.Parse(izraz.Substring((i + 1), (izraz.Length - i - 1)));
  27. }
  28.  
  29. }
  30. switch (operacija)
  31. {
  32. case "+":
  33. {
  34. Console.WriteLine("{0} + {1} = {2}", broj1, broj2, (broj1 + broj2));
  35. break;
  36. }
  37. case "-":
  38. {
  39. Console.WriteLine("{0} - {1} = {2}", broj1, broj2, (broj1 - broj2));
  40. break;
  41. }
  42. case "*":
  43. {
  44. Console.WriteLine("{0} * {1} = {2}", broj1, broj2, (broj1 * broj2));
  45. break;
  46. }
  47. case "/":
  48. {
  49. Console.WriteLine("{0} / {1} = {2}", broj1, broj2, ((float)broj1 / broj2));
  50. break;
  51. }
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement