Using C language and can’t use logical operators, relational, function calls or
ID: 3745298 • Letter: U
Question
Using C language and can’t use logical operators, relational, function calls or selection constructs can be used. Enter option 1 or 2 and then depending on options, ask to enter either "time" or "distance. Option 1 Enter "time" or Option 2 Enter "distance".
#include int main() {
int num; printf("Enter option 1 or 2: ");
scanf("%d", &num); printf(num == 1 ? "Enter time " : "Enter distance ");
return 0; }
In this coding above is "==" a logical/realtioinal operator? is there another whay with out using a relationoal/loigical operatror. I cant figure it out.
Explanation / Answer
You can use bitwise operator (bitwise AND) for this,
#include <stdio.h>
int main() {
int num;
printf("Enter option 1 or 2: ");
scanf("%d", &num);
printf(num &1 ? "Enter time " : "Enter distance ");
return 0; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.