Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
About Lesson

Write a program that takes a number as input and outputs its absolute value.

#include <stdio.h>

int main() {
// Declare variables
float number;

// Input: Get a number from the user
printf(“Enter a number: “);
scanf(“%f”, &number);

// Process: Calculate and output the absolute value
if (number < 0) {
printf(“The absolute value of %.2f is %.2fn”, number, -number);
} else {
printf(“The absolute value of %.2f is %.2fn”, number, number);
}

return 0; // Exit the program successfully
}