Auto commit
This commit is contained in:
parent
7b67a5fe21
commit
4549e5412c
@ -285,3 +285,82 @@ void main()
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### C语言-8
|
||||||
|
|
||||||
|
```c
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
【程序设计】该程序实现的功能是:求一个整数各位数字之和。(使用while实现)
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
|
||||||
|
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
int getsum(int m)
|
||||||
|
{
|
||||||
|
int i,s=0;
|
||||||
|
|
||||||
|
/**********Program**********/
|
||||||
|
while(m){
|
||||||
|
s+=m%10;
|
||||||
|
m/=10;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
/********** End **********/
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,sum;
|
||||||
|
scanf("%d",&n);
|
||||||
|
sum=getsum(n);
|
||||||
|
printf("结果是%d\n",sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### C语言-9
|
||||||
|
|
||||||
|
```c
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### C语言-10
|
||||||
|
|
||||||
|
```c
|
||||||
|
/*----------------------------------------------------------------------
|
||||||
|
【程序设计】
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
随机输入一字符串(不包含空格,长度不超过100),删除字符串中的数字字符后输出。
|
||||||
|
例输入:I will be 17 years old soon, and I will graduate from high school in June 2025
|
||||||
|
输出:
|
||||||
|
去掉数字后的字符串为:I will be years old soon, and I will graduate from high school in June
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
|
||||||
|
Program-End之间填入若干语句。
|
||||||
|
不要删除标志否则不得分。
|
||||||
|
不要修改或删除Program-End之外的内容否则不得分。
|
||||||
|
----------------------------------------------------------------------*/
|
||||||
|
#include<stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
char a[100],b[100];
|
||||||
|
int l,i,j;
|
||||||
|
gets(a);
|
||||||
|
l=strlen(a);
|
||||||
|
j=0;
|
||||||
|
/**********Program**********/
|
||||||
|
for(i=0;i<l;i++){
|
||||||
|
if(a[i] > '9' || a[i] < '0'){
|
||||||
|
b[j++] = a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/********** End **********/
|
||||||
|
b[j]='\0';
|
||||||
|
printf("去掉数字后的字符串为:");
|
||||||
|
puts(b);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user