(C syntax) input a number and output its absolute value. The syntax is a number.

Source: Internet
Author: User
Tags mathematical functions

(C syntax) input a number and output its absolute value. The syntax is a number.

Knowledge point:

If statement

 

Content: enter a number to output its absolute value.

Input description:

One integer in one row

Output description:

One integer in one row

 

Input example:

-3

Output example:

3

 

# Include <stdio. h> int main () {int a; scanf ("% d", & a); if (a <0) {a =-;} printf ("% d \ n", a); return 0 ;}

 


Entry C language: enter any integer on the keyboard and then output its absolute value.

Method 1:
// Use mathematical functions
# Include <stdio. h>
# Include <math. h>
Void main ()
{
Int;
Scanf ("% d", & );
Printf ("% d \ n", abs ());
}
Method 2:
// Judge
# Include <stdio. h>
Void main ()
{
Int;
Scanf ("% d", & );
If (a> = 0)
Printf ("% d \ n", );
Else
Printf ("% d \ n",-);
}

C language program 1 input a real number and output its absolute value 21! + 2! + ...... + 10! And the operation to calculate the factorial is defined as function 3.

L, kpki [P', k0yhj0'; l-p; '. piklp ';

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.