鱼C论坛

 找回密码
 立即注册
楼主: 小甲鱼

[课后作业] S1E2:第一个程序 | 课后测试题及答案

    [复制链接]
发表于 2024-1-8 14:46:30 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
0.计算机只懂二进制的0和1
1.机器语言
2.编译
3.解释型语言需要跨平台,而编译型语言不需要
4.能
5.解释型编程语言→字节码→解释器→cpu执行
6.编译
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-8 15:12:52 | 显示全部楼层
Q 为什么我们说计算机其实是“二傻子”?
A 他只懂得二进制的0和1
Q CPU 唯一认识的语言是什么语言?
A 机器语言
Q C 语言编写的源代码转换为汇编语言的过程叫什么?
A 编译
Q 编译型语言和解释型语言的本质区别是什么?
A 编译型语言CPU可以直接执行,解释型语言需要通过解释器解释,才能让CPU执行
Q 在 Linux 系统上用 C 语言编译的可执行程序,是否能在 Windows 系统上执行?
A 能
Q 解释型编程语言是如何实现跨平台的?
A 通过解释器进行解释,再让CPU执行
Q 莫斯密码的原理其实是什么?
A 查表
Q 视频中小甲鱼“故弄玄虚”的那段密文还原后是什么内容(中文)?
A 亲们趁敌人吃饭时发动进攻(QINMENCHENDIRENCHIFANSHIFADONGJINGONG)

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-8 15:53:54 | 显示全部楼层
计算中...
目前你总共写了127行代码!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-8 16:43:25 | 显示全部楼层

#include < io.h>
#include < direct.h>
#include < stdio.h>
#include < stdlib.h>
#include < string.h>

#define MAX        256

长总计;

int countLines(const char *文件名);
无效 findAllCodes(const char *path);
void findALLFiles(常量字符 *路径);

int countLines(常量字符 *文件名)
{
文件 *fp;
int 计数 = 0;
int 温度;
        
if ((fp = fopen(filename, “r”)) == NULL)
        {
fprintf(stderr, “无法打开文件:%s\n”, filename);
返回 0;
        }
        
而 ((temp = fgetc(fp)) != EOF)
        {
如果 (temp == '\n')
                {
计数++;
                }
        }
        
关闭(fp);
        
返回计数;
}

无效 findAllCodes(常量字符 *路径)
{
结构_finddata_t fa;
长柄;
char thePath[MAX], target[MAX];
        
strcpy(路径,路径);
if((handle = _findfirst(strcat(thePath, “/*.c”), &fa)) != -1L)
        {

                {
sprintf(target, “%s/%s”, 路径, fa.name);
总计 += countLines(target);
}while (_findnext(句柄, &fa) == 0);
        }
   
_findclose(手柄);
}

无效 findALLDirs(常量字符 *路径)
{
结构_finddata_t fa;
长柄;
char thePath[最大];
        
strcpy(路径,路径);
if((handle = _findfirst(strcat(thePath, “/*”), &fa)) == -1L)
        {
fprintf(stderr, “路径 %s 是错误的!\n”,path);
返回;
        }
   

        {        
if (!strcmp(fa.name, “.”) || !strcmp(fa.name, “..”))
继续;
                    
if( fa.attrib == _A_SUBDIR)
                {        
sprintf(thePath, “%s/%s”, 路径, fa.name);
findAllCodes(路径);
findALLDirs(路径);
                }
}while (_findnext(句柄, &fa) == 0);
   
_findclose(手柄);
}

int main()
{
char 路径[MAX] = “.”;
        
printf(“计算中...\n”);
        
findAllCodes(路径);
findALLDirs(路径);
        
printf(“目前你总共写了 %ld 行代码!\n\n”, total);
system(“暂停”);
        
返回 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-8 18:01:32 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-8 18:30:46 | 显示全部楼层
666
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-8 20:55:34 | 显示全部楼层
回复
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-8 21:49:18 | 显示全部楼层
继续来学习啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-8 23:45:57 | 显示全部楼层
aa
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-9 11:08:30 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-9 11:58:50 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-9 12:33:13 | 显示全部楼层

#include < io.h>
#include < direct.h>
#include < stdio.h>
#include < stdlib.h>
#include < string.h>

#define MAX                256

长总计;

int countLines(const char *文件名);
无效 findALLFiles(const char *path);
void findALLFiles(常量字符 *路径);

int countLines(常量字符 *文件名)
{
文件 *fg;
int 计数 = 0;
int 温度;

if ((fg = fopen (filename,"r"))==NULL)
        {
fgrintf (stderr, "无法打开文件:%s\n",filename);
返回 0;
                }
                       
而((temp = fgetc (fg))! = EOF)
        {
如果 (temp == '\n')
                                {
计数++;
                                 }
         }
         
关闭 (fg);

返回计数;
}

无效 findAllCodes (常量字符 *路径)
{
结构_finddata_t fa;
长柄;
char thePath[MAX], target[MAX];

strcpy(路径,路径);
if((handle = _findfirst (strcat (thePath, "/*.c") , &fa)) ! = -1L)
                {

                                {
sprintf (target, "%s/%s", 路径, fa.name);
总计 += countLines (target);
}while (_findnext (句柄, &fa) == 0);
                }

_findclose (手柄);
}

无效 dinddata_t fa;
{
结构_finddata_t fa;
长柄;
char thePath[最大];

stecpy (路径, 路径);
if ((handle = _findfirst (strcat (thePath, "/*") , &fa)) == -1L)
                {
fprindf (stderr,"路径 %s 是错误的!\n",path);
返回;
                 }
  

                {
if (! stecmp (fa.name, ".") || ! stecmp (fa.name, ".."))
继续;

if( fa.attrib == _A_SUBDIR)
                                {
speintf (thePath, "%s/%S", 路径, fa.name);
findAllCodes (路径);
findALLDirs (路径);
                                 }
}while (_findnext (句柄, &fa) == 0);

_findclose(手柄);
}

int main ()
{
char 路径[MAX] = ".";

printf ("计算中...\n");

findALLCodes (路径);
findALLDirs (路径);

printf ("目前你总共写了 %1d 行代码!\n\n", total);
system("暂停");

返回 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-9 12:44:31 | 显示全部楼层
为什么#include < io.h>会报错呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-9 15:43:46 | 显示全部楼层
受教!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-9 16:56:21 | 显示全部楼层
第一个程序
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-9 20:39:51 | 显示全部楼层
我敲完了!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-9 20:56:28 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-9 21:19:59 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-1-10 02:54:26 | 显示全部楼层
file:///C:/Users/ziyuexia/Desktop/%E7%AC%AC%E4%B8%80%E6%AC%A1%E4%BD%9C%E4%B8%9A.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-1-10 17:31:44 | 显示全部楼层
为啥得到的结果不对
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-5 22:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表