这个做业属于哪一个课程 | C语言程序设计ll |
---|---|
这个做业的要求 | (https://edu.cnblogs.com/campus/zswxy/SE2019-4/homework/10125) |
我在这个课程的目标 | 灵活运用C语言而且能够编写一些小的程序 |
这个做业在哪一个具体方面帮我实现目标 | 全局变量、局部变量 |
参考文献 | C语言程序设计、百度 |
本题要求实现一个函数,判断任一给定整数N是否知足条件:它是彻底平方数,又至少有两位数字相同,如14四、676等。
裁判测试程序样例:
include <stdio.h>
include <math.h>编程
int IsTheNumber ( const int N );数组
int main()
{
int n1, n2, i, cnt;函数
scanf("%d %d", &n1, &n2); cnt = 0; for ( i=n1; i<=n2; i++ ) { if ( IsTheNumber(i) ) cnt++; } printf("cnt = %d\n", cnt); return 0;
}
输入样例:105 500
输出样例:cnt = 6学习
int IsTheNumber ( const int N );测试
int main()
{
int n1, n2, i, cnt; 定义变量设计
输入n1, n2 cnt = 0; 初始化为0 for ( n1循环到n2 ) { if ( IsTheNumber(i) ) cnt++; 累加 } 输出cnt
int IsTheNumber(const int N)
{
int flag = 0 ; 判断返还
int k, m, t;
m = N;
k = sqrt(N);
if(k*k == N)
{
int a[10]={0}; 定义num的长度为10,由于传入的整数的每位数多是0~9
while( m>0)
{
t = m%10;
for(int i=0; i<10; i++)
{
if(t == i)
a[i]++;
if(a[i] == 2)
{
flag = 1;
跳出
}
}
if( flag )
跳出
m /= 10;
}
}
return flag;
}code
输入数据 | 输出数据 | 说明 |
---|---|---|
145 555 | cnt=4 | 4个平方数 |
300 600 | cnt=4 | 4个平方数 |
130 676 | cnt=6 | 6个平方数 |
编译错误:if后面忘记跳出,加上break;blog
本题要求实现两个函数:一个函数判断给定正整数的各位数字之和是否等于5;另外一个函数统计给定区间内有多少个知足上述要求的整数,并计算这些整数的和。
裁判测试程序样例:get
int is( int number );
void count_sum( int a, int b );博客
int main()
{
int a, b;
scanf("%d %d", &a, &b); if (is(a)) printf("%d is counted.\n", a); if (is(b)) printf("%d is counted.\n", b); count_sum(a, b); return 0;
}
输入样例:104 999
输出样例:104 is counted.
count = 15, sum = 3720
int is( int number );
void count_sum( int a, int b );
int main()
{
定义a,b
输入a,b if (is(a)) 输出a if (is(b)) 输出b count_sum(a, b); return 0;
}
int is( int n)
{
int s=0,t=0;
while(n!=0){
t=n%10;
n/=10;
s+=t;
}
if(s==5)
return 1;
else
return 0;
}
void count_sum( int a, int b )
{
int sum=0,count=0,i;
从a循环到b
if(is(i)){
count++;
sum+=i;
}
}
输出count,sum
}
输入数据 | 输出数据 | 说明 |
---|---|---|
135 344 | count=8,sum=1939 | 8个知足要求,总和为1939 |
100 176 | count=5,sum=610 | 6个知足要求,总和为610 |
400 510 | count=3,sum=1311 | 3个知足要求,总和为1311 |
编译错误:18行if后面忘了{},添加上去
1.与我不同,同窗定义了二个数组来进行选择
2.我用了个flag帮助判断,同窗没有直接用的式子
1.开始第一个循环我用的while循环,同窗用的do-while,先执行后判断
2.第七行我用的s+=t,运用累加,同窗是直接相加
周/星期 | 这周所花的时间 | 代码行 | 学到的知识点简介 | 目前比较迷惑的问题 |
---|---|---|---|---|
第四周 | 10h | 50 | hello world | |
第五周 | 4h | 80 | 分段函数 | |
第六周 | 8h | 120 | 华氏温度与摄氏温度转换 | 如何更加快捷转换 |
第七周 | 12h | 180 | if-else语句 | 输入、输出的一些符号 |
第八周 | 9h | 270 | for循环语句 | 小数点位数的保留 |
第九周 | 13h | 400 | 自定义函数 | 表格和图的一些格式问题 |
第十周 | 12h | 550 | 多分支else-if以及字符型 | 一些字符型表示的运算 |
第十一周 | 11h | 680 | switch语句 | 返回值被忽略的问题 |
第十二周 | 13.5h | 815 | while、do-while循环语句 | while、do-while循环语句与某些数学问题的结合使用 |
第十三周 | 11h | 910 | for语句的嵌套、break和continue语句 | for语句说明何时能够省略{} |
第十四周 | 13h | 1010 | 仍然为循环语句嵌套 | |
第十五周 | 14h | 1150 | 全局变量、局部变量 | extern扩充 |
时间 | 博客字数 | 代码行数 |
---|---|---|
第四周 | 200 | 50 |
第五周 | 400 | 80 |
第六周 | 650 | 120 |
第七周 | 1450 | 180 |
第八周 | 2100 | 270 |
第九周 | 2700 | 400 |
第十周 | 3200 | 550 |
第十一周 | 3700 | 680 |
第十二周 | 4100 | 815 |
第十三周 | 4600 | 910 |
第十四周 | 5100 | 1010 |
第十五周 | 5700 | 1150 |
1.此次学习了静态变量和自动变量
2.四种类型auto自动型、register寄存型、extern外部型、static静态型
3.全局变量能够做用于全部函数,从定义开始到结束
4.感受此次题目真的挺难的,主要是编程题
思惟导图