Hello, I'm a beginner to the C language. Today, I got assigned homework, and I need help. Below are the questions and what I got (but I do not think it is right):
I know it's an if/else statement, but I don't understand what to put (like how to write it so that just 2 or all 3 variables need to be true for a to equal 1).1) Write a C statement which will set a to 1 if at least two of the three integer variables x, y, z are true (i.e. if any two or all three are true).
2) Write a C statement to perform the following operation: if x is between -3.0 and 2.0 inclusive, set y equal to x, otherwise set y to zero.Code:if (-3.0 <= x <=2.0) y = x; else y = 0;No clue how to solve it.3) Given the initialization: double z1 = 1.0, z2 = z1/2; use z1,z2 as a two-point sliding window (i.e. z1=z2; z2=z1/2; slides the window) and write a loop to find the value of z1 such that 1 + z1 is greater than 1 but 1 + z2 is equal to 1.
I put 5. My rationale is that it'll print 0, 3, 6, 9, and 12 (it'll add 3 to 9 because 9 is less than 11; after 12 the statement is invalid). Is this right?4) How many times is the body of the following loop executed?
Code:int i, x=0; for( i = 0; i < 11; i += 3) { x += i; }
5) Write a for statement using integer counter i which will print the integer values starting at 0 and ending with 44.Code:int i; for(i = 0; i <= 44; ++i) { printf( "%i \n" , i); }
Can anyone help? I really want to learn this language. Help is much appreciated!