Saturday 5 November 2011

Write a program to read x and to compute y=1 for x>0,y=0 for x=0 and y=-1 for x

Algorithm:

 Step1:         Start


Step2:         Read the value of x.


Step3:         if (x>0) y-1 else if (x=0) y=0 else x<0) y=-1


Step4:         Print y


Step5:         Stop.



Program:

#include<stdio.h>


main()


   {


int x,y:


printf("\nEnter values for x :");


scanf("%d ",&x);


if(x>0)


                    y=1;


else if(x=0)


                    y=0;


else


                    y=-1


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


getch();


   }


Output:                           I/P                                 O/P

Enter values for x:    32                  Y =  1


Enter values for x: -2344               Y = -1

No comments:

Post a Comment