Write a program to input an integer, and if positive, change it to negative, and if negative change it to positive.
INPUT: Enter an integer: 12
Sign changed: -12
INPUT: Enter an integer: -14
Sign changed: 14
Answers
Answered by
4
Answer:
#include<studio.h>
int main()
{
int n;
scanf("%d",&n);
if(n>0)
{
n=-n;
printf("%d",n);
}
else
{
n=-n;
printf("%d",n);
}
}
Answered by
5
Write a program to input an integer and if it is positive, change into negative and if it's negative, change into positive.
import java.util.*;
class PositiveNegative
{
public static void main(String s[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n=sc.nextInt();
n = -n;
System.out.println("Sign changed: "+n);
}
}
Similar questions