Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1)Create a conditional expression that evaluates to string \"negative\" if userV

ID: 638571 • Letter: 1

Question

1)Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "positive" otherwise. Example output when userVal = -9 for the below sample program:

#include <stdio.h>
#include <string.h>

int main(void) {
char condStr[50] = "";
int userVal = 0;

userVal = -9;

strcpy(condStr, /* Your solution goes here */);

printf("%d is %s. ", userVal, condStr);

return 0;
}

2)

Using a conditional expression, write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and updateDirection is 1, numUsers becomes 9; if updateDirection is 0, numUsers becomes 7. Hint: Start with "numUsers = ...".

#include

int main(void) {
int numUsers = 0;
int updateDirection = 0;

numUsers = 8;
updateDirection = 1;

/* Your solution goes here */

printf("New value is: %d ", numUsers);

return 0;
}

Explanation / Answer

==============================

Program 1

==============================

#include <stdio.h>
#include <string.h>

int main(void) {
  
   char condStr[50] = "";
   int userVal = 0;
  
   userVal = -9;

strcpy(condStr, userVal<0?"negative":"positive");

printf("%d is %s. ", userVal, condStr);
   return 0;
}

==============================

Program 2

==============================

#include<stdio.h>
int main(void) {

   int numUsers = 0;
   int updateDirection = 0;

   numUsers = 8;
   updateDirection = 1;

numUsers= (updateDirection==1)?numUsers +1:numUsers -1;
   
   printf("New value is: %d ", numUsers);
   return 0;
}