Computer Science, asked by Prisilla, 7 months ago

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 unsolvedmystery31
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 anindyaadhikari13
5

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program to input an integer and if it is positive, change into negative and if it's negative, change into positive.

\star\:\:\:\sf\large\underline\blue{Source\:Code:-}

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