鱼C论坛

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

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

    [复制链接]
发表于 2018-12-8 19:22:42 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
yin men chen di ren chi fan shi fa dong jing ong
机器语言
编译
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-8 20:31:02 | 显示全部楼层
0.因为计算机是二进制的
1.机器语言
2.转化
3.一个难,一个容易
4.能
5.不知道
6.
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-8 20:34:50 | 显示全部楼层
感谢~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-8 20:48:02 | 显示全部楼层
C:\Users\Zhibudao\Desktop\李世杰-河北工程技术学院.截图.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-8 20:49:38 | 显示全部楼层
。。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-8 21:17:57 | 显示全部楼层
开心学C
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-8 23:03:50 | 显示全部楼层
查看参考答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-9 01:53:45 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-9 15:44:53 | 显示全部楼层
写完了啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-9 19:00:11 | 显示全部楼层
为什么我抄完是90行代码而已!
QQ图片20181209185924.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-9 21:56:42 | 显示全部楼层
第一次接触编程,希望错的不多-.-
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 13:54:58 | 显示全部楼层
真想知道
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 14:58:30 | 显示全部楼层
123123123
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 15:24:34 | 显示全部楼层
看答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 15:32:20 | 显示全部楼层
图一时之快先看答案,你将失去一次锻炼的机会!QaLrA5qFM_
u(oI{=C4h8>~-!vfjPn_c739V5,.
请先自己思考和动手,再回复查看参考答案。4H`
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 16:01:46 | 显示全部楼层
0、只能识别0-1
1、机器语言
2、编译
3、机器能否识别
4、能-C可移植性
5、C可移植性
6、0-1编码对应
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 19:59:30 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-12-10 20:52:20 | 显示全部楼层
#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 findAIICodes(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 findAIICodes(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);
                        findAIICodes(thePath);
                        findALLDirs(thePath);
                }
        }while (_findnext(handle,&fa)==0);

        _findclose(handle);
}

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

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

        findAIICodes(path);
        findALLDirs(path);

        printf("目前你总共写了%ld行代码!\n\n",total);
        system("pause");

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

使用道具 举报

发表于 2018-12-10 21:43:27 | 显示全部楼层

#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("目前你总共写了 %d 行代码!\n\n",total);
                system("pause");
               
                return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-10 22:09:14 | 显示全部楼层
哎,确实挺难的呢!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-26 06:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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