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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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