鱼C论坛

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

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

    [复制链接]
发表于 2020-10-9 16:44:02 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
0. 为什么我们说计算机其实是“二傻子”?
只懂二进制0和1
1. CPU 唯一认识的语言是什么语言?
机器码

2. C 语言编写的源代码转换为汇编语言的过程叫什么?
编译

3. 编译型语言和解释型语言的本质区别是什么?
编译型语言可直接执行;
解释型语言需要解释器,转换成中间代码, 跨平台,每次执行要进行一次翻译 效率低;
本质区别就是编译型语言效率高可直接编译成机器语言,不用每次都需要解释器转换成中间代码。

4. 在 Linux 系统上用 C 语言编译的可执行程序,是否能在 Windows 系统上执行?
内核都是C语言,可以吧我猜

5. 解释型编程语言是如何实现跨平台的?
先转换成字节码给解释器,让解释器逐字传给CPU

6. 莫斯密码的原理其实是什么?
查表

7. 视频中小甲鱼“故弄玄虚”的那段密文还原后是什么内容(中文)?
亲们趁敌人吃饭时发动进攻
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 16:45:45 | 显示全部楼层
[fishc@localhost FishC]$ ./homework
计算中...
目前你总共写了112 行代码!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 16:49:58 | 显示全部楼层
Uijin_达达 发表于 2020-10-9 16:45
[fishc@localhost FishC]$ ./homework
计算中...
目前你总共写了112 行代码!

答案是106   说明我还抄重复了几句 哈哈哈哈
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 17:01:44 | 显示全部楼层
C:\Users\yinyi\Desktop
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 17:23:18 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-9 17:36:58 | 显示全部楼层
计算行数代码运行的截图
作业1.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 17:38:16 | 显示全部楼层
谢谢大佬
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 18:38:29 | 显示全部楼层
查看参考答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 18:56:08 | 显示全部楼层
测试题答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 19:16:49 | 显示全部楼层
hh
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-9 19:25:53 | 显示全部楼层
0
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-9 19:51:38 | 显示全部楼层

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

#define MAX        256

long total;

int countLines(const char *filename);
void findAllCodes(const char *path);
void findAllFiles(const char *path);

int countLines(const char *filename)
{
        FILE *fp;
        int count = 0;
        int temp;
       
        if((fp = fopen(filename,"r")) == NULL)
        {
                fprintf(stderr,"Can not open the file:%s\n", filename);
                return 0;
        }
       
        while((temp = fgetc(fp)) != EOF)
        {
                   if (temp == '\n')
                   {
                                  count++;
                   }
        }
       
        fclose(fp);
       
        return count;
}

void findAllCodes(const char *path)
{
             struct _finddata_t fa;
             long handle;
             char thePath[MAX],target[MAX];
             
             strcpy(thePath,path);
             if((handle = _findfirst(strcat(thePath,"/*.c"),&fa)) != -1L)
             {
                          do
                          {
                                       sprintf(target,"%s/%s",path,fa.name);
                                       total += countLines(target);
                                }while (_findnext(handle,&fa) == 0);
         }
         
         _findclose(handle);
}

void findALLDirs(const char *path)
{
             struct _finddata_t fa;
             long handle;
             char thePath[MAX];
             
             strcpy(thePath,path);
             if((handle = _findfirst(strcat(thePath,"/*"),&fa)) == -1L)
             {
                          fprintf(stderr,"The path %s is wrong!\n",path);
                          return;
                 }
                 
                 do
                 {
                              if(!strcmp(fa.name,".") || !strcmp(fa.name,".."))
                                     continue;
                                    
                              if( fa.attrib == _A_SUBDIR)
                              {
                                           sprintf(thePath,"%s%s", path, fa.name);
                                           findAllCodes(thePath);
                                           findALLDirs(thePath);
                                 }
                 }while (_findnext(handle, &fa) == 0);
                 
                 _findclose(handle);
}

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

使用道具 举报

发表于 2020-10-9 20:05:48 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-9 20:25:55 | 显示全部楼层
感谢楼主无私奉献!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 20:35:26 | 显示全部楼层
运行不了?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2020-10-9 21:11:29 | 显示全部楼层

  1. #include<io.h>
  2. #include<direct.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>

  6. #define MAX    256

  7. long total;

  8. int countlines(const char *filename);
  9. void findAllCodes(const char *path);
  10. void findALLFiles(const char *path);

  11. int countlines(const char *filename)
  12. {
  13.                 FILE *fp;
  14.                 int count = 0;
  15.                 int temp;
  16.                
  17.                 if((fp=fopen(filename,"r"))==NULL)
  18.                 {
  19.                                  fprintf(stderr,"Can not open the file:%s\n",filename);
  20.                                 return 0;  
  21.                  }
  22.                  
  23.                 while ((temp=fgetc(fp))!=EOF)
  24.                 {
  25.                                 if (temp == '\n')
  26.                                 {
  27.                                         count++;
  28.                                 }
  29.                 }
  30.                
  31.                 fclose(fp);
  32.                
  33.                 return count;
  34.   }
  35.   
  36.   void findAllCodes(const char *path)
  37.   {
  38.                   struct _finddata_t fa;
  39.                 long handle;
  40.                 char thePath[MAX], target[MAX];
  41.                   
  42.                 strcpy(thePath, path);
  43.                 if((handle = _findfirst(strcat(thePath, "/*.c"), &fa)) != -1L)
  44.                   {
  45.                                   do
  46.                                   {
  47.                                                   sprintf(target, "%s/%s", path, fa.name);
  48.                                                   total += countlines(target);
  49.                                   }while (_findnext(handle, &fa) == 0);
  50.                         }  
  51.                        
  52.                         _findclose(handle);
  53.    }
  54.    
  55.    void findALLDirs(const char *path)
  56.    {
  57.                    struct _finddata_t fa;
  58.                    long handle;
  59.                    char thePath[MAX];
  60.                
  61.                 strcpy(thePath,path);
  62.                 if((handle = _findfirst(strcat(thePath,"/*"),&fa)) == -1L)
  63.                    {
  64.                             fprintf(stderr, "The path %s is wrong!\n",path);
  65.                             return;
  66.                 }
  67.    
  68.             do
  69.                 {
  70.                                 if (!strcmp(fa.name,".") || !strcmp(fa.name, ".."))
  71.                                           continue;
  72.                                           
  73.                                 if( fa.attrib == _A_SUBDIR)         
  74.                                 {
  75.                                                 sprintf(thePath, "%s/%s", path, fa.name);
  76.                                                 findAllCodes(thePath);
  77.                                                 findALLDirs(thePath);
  78.                                 }         
  79.                  }while (_findnext(handle, &fa) == 0);
  80.        
  81.                 _findclose(handle);
  82.                 }
  83.                
  84.                 int main()
  85.                 {
  86.                                 char path[MAX] = ".";
  87.                                
  88.                                 printf("计算中...\n");
  89.                                
  90.                                 findAllCodes(path);
  91.                                 findALLDirs(path);
  92.                                
  93.                                 printf("目前你总共写了 %ld 行代码! \n\n", total);
  94.                                 system("pause");
  95.                                
  96.                                 return 0;
  97.                 }

  98. 修改了好久
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 21:14:32 | 显示全部楼层
额外全额委屈恶气
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 22:10:49 | 显示全部楼层
来了来了l'l
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-9 22:30:27 | 显示全部楼层
查看参考答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-6 19:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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