Google what is meant by precedence of operators in programming?
Question 03: Google what is meant by precedence of operators in programming?
Question 04:
Arithmetic Instruction
Evaluate following examples by your own then run these on C# and compare with your result.
Example 1
int ad ;
float kot, deta, alpha, beta, gamma ;
ad = 3200 ;
kot = 0.0056 ;
alpha=1.25;
beta=35.789;
gamma=19.25;
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;
Console.WriteLine(deta);
Example 2
float si, prin, anoy, roi, avg ;
int a, b, c, num ;
si = prin * anoy * roi / 100.0 ;
avg = ( a + b + c + num ) / 4 ;
Example 3
char x, y ;
int z ;
x = 'a' ;
y = 'b' ;
z = x + y ;
Console.WriteLine(z);
Example 4
int a ;
a = Math.Pow(3,5); //Error Cannot implicitly convert type 'double' to 'int'
Console.WriteLine(a);
double a ;
a = Math.Pow(3,5);
Console.WriteLine(a);
Example 5
double a=2.45f, b=3.786f, c=2.934f ;
int s ;
s = a * b * c / 100 + 32 / 4 - 3 * 1.1 ; //Error Cannot implicitly convert type 'double' to 'int'
Console.WriteLine(s);
double a=2.45f, b=3.786f, c=2.934f ;
double s ;
s = a * b * c / 100 + 32 / 4 - 3 * 1.1 ;
Console.WriteLine(s);
g = big / 2 + big * 4 / big - big + abc / 3 ;
(abc = 2.5, big = 2, assume g to be a float)
on = ink * act / 2 + 3 / 2 * act + 2 + tig ;
(ink = 4, act = 1, tig = 3.2, assume on to be an int)
s = qui * add / 4 - 6 / 2 + 2 / 3 * 6 / god ;
(qui = 4, add = 2, god = 2, assume s to be an int)
s = 1 / 3 * a / 4 - 6 / 2 + 2 / 3 * 6 / g ;
(a = 4, g = 3, assume s to be an int)
Example 6
int x, y ;
x=Convert.ToInt32(Console.ReadLine();
y = ( x > 5 ? 3 : 4 ) ;
Console.WriteLine(y);
Example 7
char a ;
int y ;
a=Convert.ToInt32(Console.ReadLine();
y = ( a >= 65 && a <= 90 ? 1 : 0 ) ;
Console.WriteLine(y);
Example 8
int big, a, b, c ;
a=7;
b=5;
c=3;
big = ( a > b ? ( a > c ? 3: 4 ) : ( b > c ? 6: 8 ) ) ;
Console.WriteLine(big);
Example 9
int k = 35 ;
Console.WriteLine( "\n {0} {1} {2}", k == 35, k = 50, k > 40 ) ;
Question 05
Write C# programs to convert the following equations into corresponding C# statements (values of variables should be inputted by the user).
Trending now
This is a popular solution!
Step by step
Solved in 2 steps