In: Computer Science
1. Which if clause, if any, will properly determine if a dollars variable is between .01 and 1000.0, inclusive. Assume dollars is declared as a double variable.( C Programming) answer choices
if(dollars >=.01 && 1000.0)
if(dollars >= .01 and dollars <= 1000.0)
if(dollars > .01 & dollars < 1000.0)
if( (1000- dollars) < .01)
None of the above options will properly test the range
2.
Which of the following is false regarding loops?
Group of answer choices
The break statement can be used to break out of a loop.
The continue statement can be used to force the next iteration of a loop
A for loop defined as:
for(int s=0;;){}
is a syntax error
A for loop defined as:
for(int num=0; num < 2883; num++){ }
will iterate 2883 times.
A do...while loop will always iterate at least once.
3.
Given the following code, which, if any, of the following values for firstand sec will cause solution to appear on the screen?
int first;
int sec;
//assume the sec will be assigned here
if(first < -9( {
if(sec > first && sec <=0) {
printf("solution!");
}
} else {
printf("still solving...");
}
answer choices
first = -72;
sec=-1;
first = -9;
sec=-1;
first = -10;
sec=1;
first = -9;
sec=0;
None of the above values will cause solution to appear on the screen.
4. Write code(C) that will accomplish the same logic as the if stack below. Your answer must not include an if of any kind.
int hr;
printf(
"Enter hour to meet:");
scans("%d, &hr);
if(hr > 0 && hr < 4) {
printf("Too early") {;
} else if(hr == 7 || hr == 10) {
printf("I can meet");
} else {
printf("Unavailable");
}
Ans 1:
None of the above options will properly test the range.
Explaination:
Ans 2:
for(int s=0;;){} is a syntax error
Explaination:
Ans 3:
first = -72; sec = -1;
Explaination:
Ans 4:
#include<stdio.h>
int main()
{
int hr;
printf("Enter hour to meet:");
scanf("%d", &hr);
int ch=0; //check value
//convert all if ito while loop
while(hr > 0 && hr < 4)
{
printf("Too early");
ch++;
break; //exit after first execution
}
while(hr == 7 || hr == 10)
{
printf("I can meet");
ch++;
break;
}
while(ch==0) //if ch==0 no other conditions are true
{
printf("Unavailable");
break;
}
return 0;
}
.