Write a C program to switch the sign (positive to negative or negative to positive) of these values:x = 10;y = -20;z = -30;
Question
Write a C program to switch the sign (positive to negative or negative to positive) of these values:x = 10;y = -20;z = -30;
Solution
Sure, here is a simple C program that switches the sign of the given values:
#include <stdio.h>
int main() {
int x = 10;
int y = -20;
int z = -30;
x = -x;
y = -y;
z = -z;
printf("x = %d\n", x);
printf("y = %d\n", y);
printf("z = %d\n", z);
return 0;
}
This program first declares and initializes the variables x, y, and z with the given values. Then it switches the sign of each variable by negating it with the unary minus operator -. Finally, it prints out the new values of x, y, and z.
Similar Questions
Evaluate the following expressions and get the value of a, b, c and d by hand.x = 10;y = 20;z = 30;a = x++ + 10;b = --x – x--;c = ++x - ++y - ++z;d = ++y * ++y;Write a C program
.Write a C program that prompts a user for two integers and the appropriate operator(i.e. +,-,/,*) then uses switch case to determine the appropriate operation.
What will be the output of the following code? int x = 15;int y = 10;int z = 5;cout << x * x - 4 * y * z;Select the correct optionReload Math Equations -5 5 -25 25
What will be the output of the following program? int x = 20; int y = 10; double z = x++ - y * 7 / --y + x * 10; System.out.println(z);
Multiple Choice (Select 1 out of 4 options for the question below)What is the output of the C program with Modulo Division operator with – or Negative numbers?int main(){int a = -25% - 10;int b = -25% 10;int c = 25% -10;printf(“%d %d %d”, a, b, c);return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.