Advertisement
sylviapsh

Math Expression

Dec 27th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. class MathExpression
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //You are given the following mathematical expression: ....
  8.  
  9. //The sin(x) is a trigonometric function that returns the sine from the angle x (measured in radians).
  10. //The mod operator finds the remainder of division of one number by another.
  11. //Here are some examples for how the mod operator should work:
  12. //•   5 mod 2 = 1
  13. //•   5.99 mod 3 = 2
  14. //•   6 mod 3 = 0
  15. //Your task is to write a computer program that calculates the result from the shown mathematical expression, depending on the values of the variables N, M and P.
  16.  
  17.     double N = double.Parse(Console.ReadLine()),
  18.             M = double.Parse(Console.ReadLine()),
  19.             P = double.Parse(Console.ReadLine()),
  20.             result = 0.0,
  21.             upperPart = 0.0,
  22.             downPart = 0.0,
  23.             sinPart = 0.0;
  24.  
  25.     upperPart = N * N + (1 / (M * P)) + 1337;
  26.     downPart = N - (128.523123123d * P);
  27.  
  28.     sinPart = Math.Sin((int)M % 180); //The important part. The remainders should work as those for integers!!!
  29.  
  30.     result = upperPart / downPart + sinPart;
  31.  
  32.     Console.WriteLine("{0:F6}", result);
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement