C Program To Find Absolute Value of a Number

C Program To Find Absolute Value of a Number

C program to find the absolute value of a number; In this tutorial, you will learn how to find absolute value of a number in the c program with help of abs() function and arithmetic operator.

Programs To Find Absolute Value of a Number in C

  • C Program To Find Absolute Value of a Number Using abs() function
  • C Program To Find Absolute Value of a Number using Arithmetic operator

C Program To Find Absolute Value of a Number Using abs() function

#include<stdio.h>  
#include<stdlib.h>  
  
int main()  
{  
    int num;  
  
    printf("Enter a positive or negative number :- ");  
    scanf("%d", &num);  
  
    printf("Absolute Value of %d is %d\n", num, abs(num));  
  
    return 0;  
} 

C Program To Find Absolute Value of a Number using Arithmetic operator

#include<stdio.h>  
#include<stdlib.h>  
  
int main()  
{  
    int num, aNum;  
  
    printf("Enter a positive or negative number :- ");  
    scanf("%d", &num);
    if(num<0){
        aNum = (-1)*num;
        printf("Absolute Value of %d is %d\n", num, aNum); 
    }else{
        printf("Absolute Value of %d is %d\n", num, num); 
    }
  
    return 0;  
} 

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *