Skip to main content

Write a C C++ program to find absolute value of given number


Flowchart

Flowchart to find absolute value of given integer

Coding in C

#include<stdio.h>
int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    if(n<0)
    {
        n = -n;
    }
    printf("Absolute value = %d",n);
    return 0;
}

Coding in C++

#include<iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number: ";
    cin>>n;
    if(n<0)
    {
        n = -n;
    }
    cout<<"Absolute value = "<<n;
    return 0;
}

Output

Write a C C++ program to find absolute value of given integer