(C syntax) the sum of numbers and syntaxes

Source: Internet
Author: User

(C syntax) the sum of numbers and syntaxes

Knowledge point:

Usage of the character function strlen ()

ASCLL code and number conversion,-48

Flexible array usage and array name usage.

Char a [100]; int I, s = 0, m; scanf ("% s", & a); m = strlen ();

 

Content: calculates the sum of all the numbers in the input integer.

Input description:

One integer in one row

Output description:

An integer

Input example:

2147483646

Output example:

45

# Include <stdio. h> # include <string. h> int main () {char a [100]; int I, s = 0, m; scanf ("% s", & a); m = strlen (); for (I = 0; I <m; I ++) {s + = a [I]-48;} printf ("% d \ n", s ); return 0 ;}

 


Number is A of some language terms () A, syntax category B, syntax Form C, syntax meaning D, lexical category E, syntax means

B. Syntax

Enter an integer in the C language program. For example, the number of digits is 3 and the number of digits is 6.

If you do not use the log function and assume that the number of indata is a non-negative integer, you can:
Int n, s;

N = 0;
S = 0;
While (indata ){
N ++;
S + = indata % 10;
Indata/= 10;
}

The number of digits is in n and in s.

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.