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

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

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

If statement और इसके विभिन्न प्रकारो को जानने के लिए देखें—If statements in C

Flowchart to find absolute value of number

Absolute value of given number flowchart

C program to find absolute value of number

#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;
}

C++ program to find absolute value of number

#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 of C C++ program to find absolute value of number

Enter a number: -5
Absolute value = 5
Enter a number: 28
Absolute value = 28

Other branching programs in C C++

  1. Checking odd or even number (if else)
  2. Checking leap year (if else)
  3. Greater in two numbers (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer