Computer Science, asked by muthugnpth, 4 months ago

Write a c program that will read the value of x and evaluate of the following function y=1 for 0>x; 0 for x=0 ;-1 for x<0

Answers

Answered by muneebkhan928
3

Answer:

for example

int x=-1;

if(x>0) y=1;

else if (x=0) y=0;

else if (x<0) y=-1;

print(x);

Answered by varshamittal029
0

Concept:

Depending on whether the test expression is true or false,the if...else ladder allows you to check between various test expressions and statements.

Given:

y = 1 for 0 &gt; x

0 for x=0

-1 for x &lt; 0

Find:

Write a C program for the given statement.

Solution:

#include <stdio.h>

int main() {

   int x, y;

   printf("Enter the value of x: ");

   scanf("%d",&x);

   if (x &gt; 0)

      y = 1;

   else if (x &lt; 0)

       y = -1;

   else if (x == 0)

       y = 0;

   printf("y = %d",y);

   return 0;

}

Output:

Enter the value of x: 7

y = 1

Enter the value of x: -15

y = -1

Enter the value of x: 0

y = 0

Similar questions