2629881

Untitled

Feb 2nd, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.ExceptionServices;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ControlFlow
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. //Cwiczenie 1
  16. //var Excercise1 = new ex1();
  17. Console.WriteLine("{0}", ex1.mainMethod());
  18.  
  19. //Cwiczenie 2
  20.  
  21. }
  22. }
  23. }
  24.  
  25. /*
  26. Note: For all these exercises, ignore input validation unless otherwise directed. Assume the user enters a value in the format that the program expects.
  27. For example, if the program expects the user to enter a number, don't worry about validating if the input is a number or not. When testing your program, simply enter a number.
  28.  
  29. 1- Write a program to count how many numbers between 1 and 100 are divisible by 3 with no remainder. Display the count on the console.
  30.  
  31. 2- Write a program and continuously ask the user to enter a number or "ok" to exit. Calculate the sum of all the previously entered numbers and display it on the console.
  32.  
  33. 3- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console.
  34. For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5! = 120.
  35.  
  36. 4- Write a program that picks a random number between 1 and 10. Give the user 4 chances to guess the number.
  37. If the user guesses the number, display “You won"; otherwise, display “You lost". (To make sure the program is behaving correctly, you can display the secret number on the console first.)
  38.  
  39. 5- Write a program and ask the user to enter a series of numbers separated by comma. Find the maximum of the numbers and display it on the console.
  40. For example, if the user enters “5, 3, 8, 1, 4", the program should display 8.
  41. */
  42.  
  43.  
  44.  
  45. using System;
  46. using System.Collections.Generic;
  47. using System.Linq;
  48. using System.Text;
  49. using System.Threading.Tasks;
  50.  
  51. namespace ControlFlow
  52. {
  53. public class ex1
  54. {
  55. public static int mainMethod()
  56. {
  57. int timesDividable = 0;
  58.  
  59. for (int i = 1; i < 101; i++)
  60. {
  61. if (i % 3 == 0)
  62. {
  63. timesDividable++;
  64. }
  65. }
  66. return timesDividable;
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment