1 like 1 dislike
11.4k views

Write a program that reads an integer (1-4 digits) and displays the number of its digits and their sum. For example, if the number is 1234, the program should display 4 and 10

寫一個輸入四位整數 輸出數字的位數和位數的總和。例如,數字是1234程式會輸出4和10。

More information about Loops here.

 

Example input:

1234

Example output:

4 10

 

Example input 2:

245

Example output:

3 11

 

[Exercise] Coding (C) - asked in Chapter 6: Loops by (5.2k points)
ID: 28914 - Available when: 2017-10-26 18:00 - Due to: Unlimited

edited by | 11.4k views

85 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

int main(){

* * * * ** * ** a,b,c,d,e,f,g;
****** * * ** * * * ****
* * * * ****** * * **
* **** * * ** *** * ** *** *
* *** * *** ** * * ***
*** ** *** *** * * *** **
** * ** * * ** **** ***
* * **** * * **


** ** ** **** ** * ** ****** ****** *
** * ** ** *
* * ** * * *** ** * * ** **** * **
* * ***** ** * * * *


** **** * * * ** **** * %d",b,g);

return 0;

}
answered by (-301 points)
0 0
prog.c: In function 'main':
prog.c:6:6: error: statement with no effect [-Werror=unused-value]
     b==0;
     ~^~~
cc1: all warnings being treated as errors
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main (void)
{
** * * *** * * ** ** *** n, count, sum, remainder;
* *** *** * ** **** = 0;
**** * **** ** ****** * *** = 0;
**** * * *** ** *** **** * * * * * *** &n);
**** * * ** ** ** ** = n;
**** * * * ** * **** * (n != 0)
**** ** * * ** *****
** *** * **** * *** * * * * **** * * * * * *
* * ***** * * * * * * * * * ** *** = n % 10;
***** *** * ** ** * * *** * ** * ** * = sum + remainder;
** * * **** ** * ** * * * * ******* ** ** * ** /= 10;
** ** ****** * * ** * *** * ** *


* ** **** ** ***** *
* ** * * ** * ** ****** %d", count, sum);
}
answered by (-140 points)
0 0
prog.c: In function 'main':
prog.c:8:5: error: 't' undeclared (first use in this function)
     t = n;
     ^
prog.c:8:5: note: each undeclared identifier is reported only once for each function it appears in
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main(){

** ** * ** * ** * * a,b,c,d,e,f,g;
* * * *** **** *
**** * ** ** *
* * ** ** * **** * ***
* * ** * ***** * *
** * * * * ** * * * ** * *
* *** * * * **** * *
******** * * *** ** *** *** ***


*** * * * * * * * **** * **** *
**** *** * *** ** * * **
* * ** ** ** * ** * **** ***** * ** * * ***
** * ** ****


* ** * * * *** * * ** * ** * %d",b,g);

return 0;

}
answered by (-301 points)
0 0
prog.c: In function 'main':
prog.c:6:6: error: statement with no effect [-Werror=unused-value]
     b==0;
     ~^~~
cc1: all warnings being treated as errors
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main ()

{
*** * ** * **** ******* * e=0,n,nn,digit,sum=0;

** ** * * ** * * ** **** * ** ** *** *** *
* * * *** ** * *** * ** * * = n;
* ** ** ** *** * ** * (n!=0)
******* ***** ***** *
* * *** * * * * ** ** * * *** * ***
*** *** ******* ** * * * ***** ** **** * * * *
* ** * * * * *** ** **
* * **** * ****** * * * ** (nn!=0)
    {
** * ** * * * *** ******* *** ** ** ** ****** * **
**** ****** * * ** *** ** * ** ** ** ** ** *
** **** * ** * * *** * ****** *** ** ****** * * *** *
**** * *** * **** *


** * * **** * * * ** %d",e,sum);

* * * *** ** ** * ** * 0;

}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
* * ****** * ** *** * ** a,sum=0,digit=0;
* * ** ** * * ** **** ** ** ** * * **** ***

* *** * *** * *
* ** * * ***** * * **
** **** ** *** **** ** * * * *** * **** += a%10;
** ** ** * * *** * ****** * ** ** * * * /= 10;
* * ** * *** * *** ** * * * * ** **
** * * ** ** ** ** ** **
* ***** * * * *** ** * ** ****

** **** **** * * *** * * * * * * %d",digit,sum);

**** ** *** ** *** * *** * 0;
}
answered by (-281 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
* * * * * ** * * * *** * * count=0, n,sum=0,remainder;
*** ** * * ***** * * *** *** ** ** *** *** ** * * n);
* *** ***** * * ****** * ******
** * * ****** **** * * * * ***

* ****** ** *** * ** **** * ** ** **** = n % 10;
*** * *** * ** ***** * *** * * * * * * * + remainder;
*********** * ****** *** **** **** *** * ****** **** * * **
** * * * * ** * ** * *** * ***** * **** **
** ** * ** ***** * *** *
** * *** ** *** *** * *** *** **** * *** %d",count,sum);


}
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
* ***** * ** *** ** * * a;
* * **** * ** ***** * * sum=0;
* ** * * ** * ***** i=0;
* * ****** * ** * * * * *** ** * * * *
** * ** * * ** * * * (a!=0)
* * ** ** * ***
** * ** *** * * **** ** ** ** ** ** ** ** * += a%10;
** ** **** * * ** * * ** ** * * * * * * *
** ** ** * * *** * ** * ** ** * ***** * ** **
****** * *** * ** ** ***
***** ** *** * *** * ** **** *** %d",i,sum);
* * *** ** * ******** ** 0;
}
answered by (-127 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
* * * * * * * * ***** * x,y,z,r,n,digits=0,sum=0;
* **** * **** * * ** * ******
* * * * * ** ** ***
** ** *** * * ** * *** ** * **
****** ** ** ** ** ** ** *
* * * **** * ** **** ** * * *
* * * **** * * * * *** *
* * *** * * ** ** * ** **** *
* ** * * * ******** ** ** * ** *** ** *
* ** ** * * * * ******* (n>0);
* * ** ****** * * * ** ** * * ** ** * * ** ** ** *
** ** * ** ** * ** * ** * * 0;
}
answered by (-498 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
** **** * * * *




int main *
{



int * * **** ** *

* * * * * **** ** **


* * !=0){


* * ** *** * ** * **

** *** * *
****** *** ** * ** *** *** * * ***

}

* * * * * * * ** *


** **** *** * *** ** ** * 0;

}
answered by (-107 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
**** * *** * * * * ** * number = 0;

** ** ** *** ***** * ** * * **** ** * * &number);

** * *** * ** *** *** * number > 999 )
** * * * *** *
* ** ** * * * **** ** * ** *** ********* * * * * * *** * ");
* * ***** ***** ** ***
*** ***** *** ******** if( number > 99 )
* ** * *
** * * *** ** ** * * * *** ** ***** ****** *** * ");
* * * ** ******
** * ** **** * * * * *** if( number > 9 )
*** ** * ** *** * ***
** ** *** * * *** * *** * * ******* * **** ** * * ");
**** * ** ** *** *** * *
* * *** ***** ** *** ** *
* * * * * ** * ** **
* ******* * * *** ** ** ***** ******** ** * ** *** * ** * ");
* * ** ** *** **
*** * *** ** ** * ** * a,b,c,d,e;
* * * ** * * = number;
** ** * ** **** * * * = e / 1000;
* ** *** ** ** = (e/100)%10;
** * * ** ** * **** = (e/10)%10;
****** ** *** * ****** * * = e%10;
***** *** **** *** ** * * * **** *** a+b+c+d);
* *** ** * * * * * ** * * 0;
}
answered by (-285 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 0
can you replace 4 if statements with 1 loop?
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.255.96
©2016-2025

Related questions

0 like 0 dislike
69 answers
[Exercise] Coding (C) - asked Oct 26, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 28913 - Available when: 2017-10-26 18:00 - Due to: Unlimited
| 8.8k views
2 like 0 dislike
64 answers
[Exercise] Coding (C) - asked Oct 19, 2017 in Chapter 4: Expressions by thopd (12.1k points)
ID: 27669 - Available when: Unlimited - Due to: Unlimited
| 12.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users