Pogram to find absloute value of given number
- Write a program to find absolute value of a number in C
- Write a program to find absolute value of a number in C++
- Write a program to find absolute value of a number in Python
- Write a program to find absolute value of a number in PHP
- Write a program to find absolute value of a number in Java
- Write a program to find absolute value of a number in Java Script
- Write a program to find absolute value of a number in C#
Explanation:
Finding a number’s distance from zero on a number line is the first step in the logic for calculating its absolute value. This entails changing any negative integer to its corresponding positive number while maintaining zero and positive numbers.
Steps:
Input the Number:
- Take a number as input.
Check the Sign:
- If the number is negative, multiply it by −1-1−1 to make it positive.
- If the number is positive or zero, keep it as is.
Output the Absolute Value:
- Display or return the result.
Pogram to find absloute value of given number
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> #include <stdlib.h> // for abs() int main() { int num = -10; printf("Absolute value of %d is %d\n", num, abs(num)); return 0; }
#include <iostream> #include <cmath> // for std::abs int main() { int num = -10; std::cout << "Absolute value of " << num << " is " << std::abs(num) << std::endl; return 0; }
num = -10 print(f"Absolute value of {num} is {abs(num)}")
<?php $num = -10; echo "Absolute value of $num is " . abs($num) . "\n"; ?>
public class Main { public static void main(String[] args) { int num = -10; System.out.println("Absolute value of " + num + " is " + Math.abs(num)); } }
let num = -10; console.log(`Absolute value of ${num} is ${Math.abs(num)}`);
using System; class Program { static void Main() { int num = -10; Console.WriteLine($"Absolute value of {num} is {Math.Abs(num)}"); } }