《C Primer Plus》第16章复习题与编程练习

C Primer Plus 第六版 第11章 编程答案 C Primer Plus 第六版 第11章 编程答案 1.第1题 #include <stdio.h> #define SIZE 10 char * getnchar(char *, int); int main(void) { char st[SIZE]; char * sts; printf("请输入:"); sts = getnchar(st, SIZE - 1); if (sts == NULL) puts("输入失败"); 阅读详情

《C Primer Plus》第16章复习题与编程练习

复习题

1. 下面的几组代码由一个或多个宏组成,其后是使用宏的源代码。在每种情况下代码的结果是什么?这些代码是否是有效代码?(假设其中的变量已声明)

a.

#define FPM 5280 /*每英里的英尺数*/ 
dist = FPM * miles; 

b.

#define FEET 4 
#define POD FEET + FEET 
plort = FEET * POD; 

c.

#define SIX = 6; 
nex = SIX; 

d.

#define NEW(X) X + 5 
y = NEW(y); 
berg = NEW(berg) * lob; 
est = NEW(berg) / NEW(y); 
nilp = lob * NEW(-berg);

答:

a.

有效。dist = 5280 * miles

b.

有效。plort = 4 * 4 + 4

c.

无效。

d.

有效。y = y + 5
有效,但可能有误。est = berg + 5 * lob
有效,但可能有误。est = breg + 5 / y + 5
有效(传递进去的是负值不是一个符号加变量)。 lob * (-berg) + 5

2. 修改复习题1中d部分的定义,使其更可靠

答:

#define NEW(X) ((X) + 5)//尽可能地多使用括号将宏函数的变量括起

3. 定义一个宏函数,返回两值中的较小值

#define MIN(X, Y) ((X) > (Y) ? (Y) : (X))

4. 定义EVEN_GT(X, Y)宏,如果X为偶数且大于Y,该宏返回1

#define EVEN_GT(X, Y) ((X) % 2 == 0 && (X) > (Y) ? 1 : 0)

5. 定义一个宏函数,打印两个表达式及其值。

例如,若参数为3 + 4和4 * 12,则打印:

3 + 4 is 7 and 4 * 12 is 48

答:

#define SHOW(X, Y) printf(#X " is %d and " #Y " is %d\n", X, Y)

6. 创建#define指令完成下面的任务。

a.创建一个值为25的命名常量。
b.SPACE表示空格字符。
c.PS()代表打印空格字符。
d.BIG(X)代表X的值加3。
e.SUMSQ(X, Y)代表X和Y的平方和。

答:

a. #define SIZE 25
b. #define SPACE ’ ’
c. #define PS() printf(" ")
d. #define BIG(X) ((X) += 3)
e. #define SUMSQ(X,Y) ((X)(X)+(Y)(Y))

7. 定义一个宏,以下面的格式打印名称、值和int类型变量的地址:

name: fop; value: 23; address: ff464016

答:

#define SHOW(X) printf(“name:”#X";value:%d;address:%p", X, &X)

8. 假设在测试程序时要暂时跳过一块代码,如何在不移除这块代码的前提下完成这项任务?

#define DROP//如果不需要跳过代码,则删除该指令
#ifndef DROP
/*被跳过的代码块*/
#endif

9. 编写一段代码,如果定义了PR_DATE宏,则打印预处理的日期

#ifdef PR_DATE
	printf("%s\n", _ _DATE_ _);
#endif

10. 内联函数部分讨论了3种不同版本的square()函数。从行为方面看,这3种版本的函数有何不同?

第一个正常返回一个double类型的数,输入1.3时,返回值为1.69。
第二个在返回之前将结果强制转化为了int型,丢失精度。在返回转换时,返回值的小数部分全为0,输入1.3时,程序中返回值为1
第三个也在返回之前也将结果强制转化为int型,但在强制转化前结果加上了0.5,当输入为1.3时,返回值为2,输入为1.2时,返回值为1,以此来判断是调用了哪一个函数

11. 创建一个使用泛型选择表达式的宏,如果宏参数是_Bool类型,对"boolean"求值,否则对"not boolean"求值

答:

#define BOOL(X) _Generic((X), _Bool : "boolean", default : "not boolean")

12. 下面的程序有什么错误

#include <stdio.h> 
int main(int argc, char argv[]) 
{ 
    printf("The square root of %f is %f\n", argv[1],sqrt(argv[1]) ); 
}

答:

argv[] 应该改为 *argv[]
第一个%f应该改为%s
第二个argv[1]应当使用类似于atof()的函数转换为float型
应当在头文件中加上math.h
程序在使用sqrt应该排除参数是负数

13. 假设 scores 是内含 1000 个 int 类型元素的数组,要按降序排序该数组中的值。假设你使用qsort()和comp()比较函数。

a.如何正确调用qsort()?
b.如何正确定义comp()?

答:

a.

qsort((void*)scores, (size_t)1000, sizeof(int), comp);

b.

int comp(const void *a, const void *b)
{
    return (*(int*)a) - (*(int*)b);
}

14. 假设data1是内含100个double类型元素的数组,data2是内含300个double类型元素的数组。

a.编写memcpy()的函数调用,把data2中的前100个元素拷贝到data1中。
b.编写memcpy()的函数调用,把data2中的后100个元素拷贝到data1中。

答:

a. memcpy(data1, data2, 100 * sizeof(double));
b. memcpy(data1, data2 + 200, 100 * sizeof(double));

编程练习

1. 开发一个包含你需要的预处理器定义的头文件

代码:

#ifndef DRAFT_ALLDEFINE_H
#define DRAFT_ALLDEFINE_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>

#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#define MIN(X, Y) ((X) > (Y) ? (Y) : (X))

#endif // !DRAFT_ALLDEFINE_H

2. 调和平均数的宏定义

两数的调和平均数这样计算:先得到两数的倒数,然后计算两个倒数的平均值,最后取计算结果的倒数。使用#define指令定义一个宏“函数”,执行该运算。编写一个简单的程序测试该宏。

代码:

#include <stdio.h>
#include <stdlib.h>

#define HARMONIC_MEAN(X, Y) 2 / (1 / (X) + 1 / (Y))

int main()
{
    float a, b;
    printf("Please give me two numbers, and I'will calculate the harmonic mean: ");
    scanf("%f %f", &a, &b);

    printf("The harmonic mean of %.2f and %.2f is %.2f.\n", a, b, HARMONIC_MEAN(a, b));

    system("pause");
    return 0;
}

运行结果:

在这里插入图片描述

3. 极坐标变换

极坐标用向量的模(即向量的长度)和向量相对x轴逆时针旋转的角度来描述该向量。直角坐标用向量的x轴和y轴的坐标来描述该向量(见图16.3)。编写一个程序,读取向量的模和角度(单位:度),然后显示x轴和y轴的坐标。相关方程如下:

x = r*cos A
y = r*sin A

需要一个函数来完成转换,该函数接受一个包含极坐标的结构,并返回一个包含直角坐标的结构(或返回指向该结构的指针)。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.1415926

struct Rectangular translate(struct Polar p);
void show_polar(const struct Polar p);
void show_rectangular(const struct Rectangular r);

struct Polar // 极坐标
{
    float r;
    float A;
};

struct Rectangular // 直角坐标
{
    float x;
    float y;
};

int main()
{
    struct Polar polar;
    struct Rectangular rec;

    printf("please input the length and angle of the vector:\n");
    scanf("%f %f", &polar.r, &polar.A);
    show_polar(polar);
    rec = translate(polar);
    show_rectangular(rec);

    system("pause");
    return 0;
}

struct Rectangular translate(struct Polar p)
{
    struct Rectangular r;

    r.x = p.r * cos(p.A * PI / 180.0);
    r.y = p.r * sin(p.A * PI / 180.0);

    return r;
}

void show_polar(const struct Polar p)
{
    printf("length: %.2f, angle: %.2f°\n", p.r, p.A);
}

void show_rectangular(const struct Rectangular r)
{
    printf("x: %.2f, y: %.2f\n", r.x, r.y);
}

运行结果:

在这里插入图片描述

4. clock()函数

ANSI库这样描述clock()函数的特性:

#include <time.h>
clock_t clock (void);

这里,clock_t是定义在time.h中的类型。该函数返回处理器时间,其单位取决于实现(如果处理器时间不可用或无法表示,该函数将返回-1)。然而,CLOCKS_PER_SEC(也定义在time.h中)是每秒处理器时间单位的数量。因此,两个 clock()返回值的差值除以 CLOCKS_PER_SEC得到两次调用之间经过的秒数。在进行除法运算之前,把值的类型强制转换成double类型,可以将时间精确到小数点以后。编写一个函数,接受一个double类型的参数表示时间延迟数,然后在这段时间运行一个循环。编写一个简单的程序测试该函数。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void delay(double a);

int main()
{
    double a;

    printf("Enter a number of seconds(q to quit): ");
    while (scanf("%lf", &a) == 1)
    {
        delay(a);
        printf("Enter a number of seconds(q to quit): ");
    }
    printf("Bye!\n");
    system("pause");
    return 0;
}

void delay(double a)
{
    double s = (double)clock();
    double f = 0;
    while ((a - f) > 0.00000001)
    {
        f = ((double)clock() - s) / CLOCKS_PER_SEC;
    }
    printf("%.2lfs have passed.\n", f);
}

运行结果:

在这里插入图片描述

5. 从数组中随机选择指定数量的元素,并打印它们

编写一个函数接受这些参数:内含int类型元素的数组名、数组的大小和一个代表选取次数的值。该函数从数组中随机选择指定数量的元素,并打印它们。每个元素只能选择一次(模拟抽奖数字或挑选陪审团成员)。另外,如果你的实现有time()(第12章讨论过)或类似的函数,可在srand()中使用这个函数的输出来初始化随机数生成器rand()。编写一个简单的程序测试该函数。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define LEN 10

void Print_sd(int *, int, int);
int Find_df(int *, int);

int main()
{
    srand(time(0));

    int data[LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int count;

    printf("Enter a number, I'll pick you randomly(enter q to quit):\n");
    while (scanf("%d", &count) && count <= 10)
    {
        // printf("%d", count);
        Print_sd(data, LEN, count);
    }

    printf("Bye!\n");

    system("pause");
    return 0;
}

void Print_sd(int *ar, int n, int count)
{
    int index[LEN] = {0};
    int i = 0;

    printf("The result of random selection: ");
    while (i < count)
    {
        index[i] = Find_df(index, n);
        // printf("%d ", index[i]);
        printf("%d ", ar[index[i] - 1]);
        i++;
    }
    printf("\n");
}

int Find_df(int *index, int n)
{
    int key = rand() % 10 + 1;

    //    printf("%d", key);
    for (int i = 0; i < n; i++)
        if (key == index[i]) // 如果找到相同的下标,就向下递归
        {
            key = Find_df(index, n);
            break;
        }

    return key;
}

运行结果:

在这里插入图片描述

6. 修改程序清单16.17,使用struct names元素

修改程序清单16.17,使用struct names元素(在程序清单16.17后面的讨论中定义过),而不是double类型的数组。使用较少的元素,并用选定的名字显式初始化数组。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define NUM 100
#define LEN 40

struct Name
{
    char first[LEN];
    char last[LEN];
};

struct Name staff[NUM];

void fillarray(struct Name ar[], int n);
void showarray(const struct Name ar[], int n);
int mycomp(const void *p1, const void *p2);

int main()
{
    fillarray(staff, NUM);
    puts("Random list:");
    showarray(staff, NUM);
    qsort((void *)staff, (size_t)NUM, sizeof(struct Name), mycomp);
    puts("\nSorted list:");
    showarray(staff, NUM);

    system("pause");
    return 0;
}

void fillarray(struct Name ar[], int n)
{
    srand((unsigned long)time(0));

    for (int i = 0; i < n; i++)
    {
        int firstLen = rand() % 10 + 1;
        int lastLen = rand() % 10 + 1;
        // 随机生成first
        for (int j = 0; j < firstLen; j++)
        {
            ar[i].first[j] = rand() % 26 + 'a';
        }
        // 随机生成last
        for (int j = 0; j < lastLen; j++)
        {
            ar[i].last[j] = rand() % 26 + 'a';
        }
    }
}

void showarray(const struct Name ar[], int n)
{
    int i;

    for (i = 0; i < n; i++)
    {
        printf("%10s.%-10s ", ar[i].first, ar[i].last);
        if (i % 4 == 3)
            putchar('\n');
    }
    if (i % 4 != 0)
        putchar('\n');
}

int mycomp(const void *p1, const void *p2)
{
    const struct Name *ps1 = (const struct Name *)p1;
    const struct Name *ps2 = (const struct Name *)p2;
    int res = strcmp(ps1->last, ps2->last);

    if (res != 0)
        return res;
    else
        return strcmp(ps1->first, ps2->first);
}

运行结果:

C:\Users\81228\Documents\Program\VScode C Program\chapter16>16.6
Random list:
 zljeezddl.in              cwytt.hdtagwq    xmeukcamly.vjkgkkii         npuh.hrhvis     
  caxadvqb.lf                asf.puhpvvd       ldidgum.g            lctizmdm.rnr        
  ipdafwiv.bcaofo     vvabbuqylv.bm              rdipz.soahbrqg       ovnnzv.g
  kpjekesh.jhzmnmwh    dpzmepdnw.enkmhjz        cqoemj.nbojoonr         mcqm.clqauva    
      csqr.ovlmxyuamf       jiyp.mlnhp          zmadux.stszk         ycohuah.qpy        
       gie.dgg         tfgglmtcb.ozcmibpkpa   uwcfxxcm.hvujzr          bovtp.xrmyadnd
   enqnrlz.jkzmxbsi       ntxnyw.uhpum      uobllmhluj.ixwhn           zshca.lsuokfu
    osqrvl.ccilrqfl   svcennyfwx.zzyycfiix     uqwoxrh.v                  og.hzssx
     rdswg.k               joktr.edm          pttefhmm.ki                 mi.cip
   mhielxt.qdjzixk     rvchhwiyy.gj              nvsui.zreupwvm   qgvrutmbao.z
     itoeq.jrnoxil             z.fnlq         eyoyblsp.jxqoaupbfo    eysgmne.egcezy     
  upumzuhb.i               xwbgj.s                  lq.pl                 cy.baqbirsxx
         i.kwr          foktbczo.gi              qvfqh.pcg           avwnrye.xjpg
      jzfe.z               bznxq.gfcqkvhbp           w.agmzauzcml vbswqcdook.thxhrruanf
     xtcqq.trxnctf         qxgok.iefpavd          ixym.vgyviq            ryv.rcurez
     kashj.vlf        hpertiqynm.pk            unsoezl.ioqph        mzmmxiao.wzmwluvk
      bbnr.mihjc           gtgvz.iccmltrru         xfu.qc                 fv.dzbk
    trixyn.idcat              vu.oyjielzi         isnt.yagoiaity   qkydpctgw.ngppmnkex
ymhafpltrz.ziyifn              q.c          epbanewzmw.jd            rbetyax.ujpqpliz
fwvjhpterm.th              zzxli.agikkic      nlooufyt.pp                  d.hkyye
      tgxt.vffv        ubsbanlok.kpoxdgp         tmicu.q                   l.l
     xxwez.ozqd       myxzsgwjyg.bbwygsi      ktqrvbmt.ro              sssuf.xx
         s.agmdsk           wlpo.bipdjysce           q.mb             mvemkw.dbyh
   jvestub.aqi           plwttjy.dy                 sn.answyswc        qpbht.kxlm
         w.nwdvd             ifa.cjeqsvfat    qqesohik.bn         thdydiqblr.elyas

Sorted list:
     zzxli.agikkic             s.agmdsk              w.agmzauzcml         sn.answyswc
   jvestub.aqi                cy.baqbirsxx  myxzsgwjyg.bbwygsi      ipdafwiv.bcaofo
      wlpo.bipdjysce  vvabbuqylv.bm           qqesohik.bn                  q.c
    osqrvl.ccilrqfl           mi.cip               ifa.cjeqsvfat        mcqm.clqauva
    mvemkw.dbyh              gie.dgg           plwttjy.dy                 fv.dzbk
     joktr.edm           eysgmne.egcezy     thdydiqblr.elyas       dpzmepdnw.enkmhjz    
         z.fnlq          ldidgum.g              ovnnzv.g               bznxq.gfcqkvhbp
  foktbczo.gi          rvchhwiyy.gj              cwytt.hdtagwq             d.hkyye
      npuh.hrhvis       uwcfxxcm.hvujzr             og.hzssx        upumzuhb.i
     gtgvz.iccmltrru      trixyn.idcat           qxgok.iefpavd     zljeezddl.in
   unsoezl.ioqph      uobllmhluj.ixwhn      epbanewzmw.jd           kpjekesh.jhzmnmwh
   enqnrlz.jkzmxbsi        itoeq.jrnoxil      eyoyblsp.jxqoaupbfo      rdswg.k
  pttefhmm.ki          ubsbanlok.kpoxdgp             i.kwr             qpbht.kxlm
         l.l            caxadvqb.lf              zshca.lsuokfu             q.mb
      bbnr.mihjc            jiyp.mlnhp          cqoemj.nbojoonr    qkydpctgw.ngppmnkex
         w.nwdvd            csqr.ovlmxyuamf         vu.oyjielzi    tfgglmtcb.ozcmibpkpa
     xxwez.ozqd            qvfqh.pcg        hpertiqynm.pk                 lq.pl
  nlooufyt.pp                asf.puhpvvd         tmicu.q                 xfu.qc
   mhielxt.qdjzixk       ycohuah.qpy               ryv.rcurez       lctizmdm.rnr
  ktqrvbmt.ro              xwbgj.s               rdipz.soahbrqg       zmadux.stszk
fwvjhpterm.th         vbswqcdook.thxhrruanf      xtcqq.trxnctf        ntxnyw.uhpum
   rbetyax.ujpqpliz      uqwoxrh.v                tgxt.vffv             ixym.vgyviq
xmeukcamly.vjkgkkii        kashj.vlf          mzmmxiao.wzmwluvk      avwnrye.xjpg
     bovtp.xrmyadnd        sssuf.xx               isnt.yagoiaity        jzfe.z
qgvrutmbao.z          ymhafpltrz.ziyifn          nvsui.zreupwvm   svcennyfwx.zzyycfiix
请按任意键继续. . .

C:\Users\81228\Documents\Program\VScode C Program\chapter16>

7. show_array()和new_d_array()函数

下面是使用变参函数的一个程序段:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
void show_array(const double ar[], int n);
double * new_d_array(int n, ...);
int main()
{
    double * p1;
    double * p2;
    p1 = new_d_array(5, 1.2, 2.3, 3.4, 4.5, 5.6);
    p2 = new_d_array(4, 100.0, 20.00, 8.08, -1890.0);
    show_array(p1, 5);
    show_array(p2, 4);
    free(p1);
    free(p2);
    return 0;
}

new_d_array()函数接受一个int类型的参数和double类型的参数。该函数返回一个指针,指向由malloc()分配的内存块。int类型的参数指定了动态数组中的元素个数,double类型的值用于初始化元素(第1个值赋给第1个元素,以此类推)。编写show_array()和new_d_array()函数的代码,完成这个程序。

代码:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void show_array(const double ar[], int n);
double *new_d_array(int n, ...);

int main()
{
    double *p1;
    double *p2;

    p1 = new_d_array(5, 1.2, 2.3, 3.4, 4.5, 5.6);
    p2 = new_d_array(4, 100.0, 20.00, 8.08, -1890.0);
    show_array(p1, 5);
    show_array(p2, 4);
    free(p1);
    free(p2);

    system("pause");
    return 0;
}

void show_array(const double ar[], int n)
{
    for (int i = 0; i < n; ++i)
    {
        printf("%.2lf ", ar[i]);
    }
    printf("\n");
}

double *new_d_array(int n, ...)
{
    va_list ap;      // 声明一个对象储存参数
    va_start(ap, n); // 把ap初始化为参数列表
    double *array = (double *)malloc(n * sizeof(double));

    for (int i = 0; i < n; i++)
        array[i] = va_arg(ap, double); // 访问参数列表中的每一项
    va_end(ap);

    return array;
}

运行结果:

在这里插入图片描述

C Primer Plus(第6版)第十六章复习题答案 16.7 a.dist = 5280 * miles; 有效 b.plort = 4 * 4 + 4; 有效 c. nex = = 6; 无效 d.y = y + 5; 有效 #define NEW(X) ((X) + 5) #define MIN(X, Y) ((X) &gt; (Y) ? (X) : (Y)) #define EVEN_GT(X, Y) ((X... 阅读详情

相关推荐

C Primer Plus(第6版)第十章复习题答案

10.12复习题 下面的程序将打印什么内容? 应该会打印出ref数组元素的值,一行俩 #include &amp;amp;lt;stdio.h&amp;amp;gt; int main(void) { int ref[] = {8, 4, 0, 2}; int * ptr; int index; for (index = 0, ptr = ref; index &amp;amp;lt; 4; index++, ptr++) p...

weixin_42912350的博客 2832

C语言使用宏函数返回两值中较小的值

代码】C语言使用宏函数返回两值中较小的值。

qq_45950276的博客 2206

自制非接触式静电探测仪:从振动电容原理到微弱信号检测实践

微弱信号检测是电子测量领域的核心挑战之一,尤其在需要避免物理接触或防止干扰的场景中。其基本原理在于将难以直接获取的微小物理量(如电流、电压)通过传感器转换为电信号,再经过放大、滤波等处理进行提取。锁相放大技术是解决这一问题的关键手段,它利用参考信号与目标信号的同步性,从强噪声背景中恢复出有效信息,极大提升了信噪比和测量灵敏度。这项技术的工程价值在于实现了对纳安级电流、微伏级电压等高难度参数的可靠测量。在静电防护、材料表面电位分析、生物电信号采集等应用场景中,非接触式测量需求广泛。本文聚焦的基于振动电容原理的

weixin_32349093的博客 287

C++ Primer Plus习题及答案-第十六章

习题选自:C++ Primer Plus(第六版) 内容仅供参考,如有错误,欢迎指正 !

jianmo的博客 1311

【网络协议】TCP的拥塞控制机制

前言 计算机网络中的带宽、交换节点中的缓存和处理机等,都是网络的资源,在某段时间内,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就要变坏,这种情况就叫做拥塞。 所谓拥塞控制,就是防止过多的数据注入到网络中,从而使网络中的路由器或链路不致过载。要注意用拥塞控制与流量控制的区别,拥塞控制是一个全局性的过程,涉及到所有的额主机、路由器,以及与降低网 拥塞控制的算法有:慢开始、拥塞避免、快重传、快恢复四种。 慢开始和拥塞避免 发送方维持一个拥塞窗口的状态变量,其大小取决于网络的拥塞程度

兰亭风雨的专栏 1万+

揭秘Synopsys EDA中的AI黑科技:DSO.ai如何改变传统芯片设计流程

本文深入探讨了Synopsys EDA中的AI黑科技DSO.ai如何革新传统芯片设计流程。通过数据驱动的方法论、功耗优化革命和时序收敛智能加速,DSO.ai显著提升了设计效率和质量,实现了从经验驱动到AI驱动的范式转变。文章还提供了实战指南,帮助团队跨越AI EDA的实施鸿沟。

weixin_29296241的博客 533

《C Primer Plus》第11章复习题与编程练习

《C Primer Plus》第11章复习题与编程练习

ProgramNovice的博客 1641

高分创新点!Mamba+CNN结合,发顶会首选!

研究摘要 近期视觉领域涌现CNN与Mamba的融合架构,通过双分支设计互补优势。ConvMamba结合CNN的局部特征提取与Mamba的全局建模能力,在ImageNet分类任务中实现90.2%准确率,推理速度提升1.8倍。医学图像方向,PGM-UNet引入提示引导残差Mamba模块,结合多尺度空洞卷积与KANs,显著提升分割精度;遥感领域CM-UNet通过CSMamba块与多尺度注意力聚合模块,有效捕捉长距离依赖。这些工作表明,跨模态轻量化融合与注意力优化是未来重要方向。

m0_73122726的博客 1019

《C Primer Plus》第10 章复习题和编程练习

《C Primer Plus》第 10 章复习题和编程练习

潇雪的博客 1521

LaTeX伪代码字体大小调整全攻略:从algorithm到algorithm2e的实战技巧

本文详细介绍了在LaTeX中调整伪代码字体大小的全面技巧,涵盖algorithm、algorithmicx和algorithm2e等主流算法包的使用方法。从基础命令到高级配置,帮助用户解决学术论文和技术文档中的伪代码排版问题,提升算法展示的专业性和可读性。特别针对不同期刊格式要求,提供了实用的字体调整方案。

weixin_29297127的博客 441

【二 Deepseek+Coze案例】【 2.2 Coze + Deepseek 实现小红书爆款笔记:打造专属Agent智能体】

摘要 本文介绍了如何利用Coze平台和Deepseek模型构建自动化Agent智能体,用于生成和优化小红书爆款笔记。文章首先分析了爆款笔记的核心特征,包括精准定位、吸引标题、实用内容、精美排版和热门标签。随后提出Agent智能体的功能需求,涵盖热点追踪、内容生成与优化、数据分析及自动发布等模块。在技术实现上,详细阐述了从环境配置、数据采集到内容生成与优化的全流程,并提供了Python代码示例,展示如何调用Coze函数获取热点数据及竞品笔记。该方案通过智能化的内容创作与运营策略,帮助用户高效打造高曝光的小红书

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 2333

《C Primer Plus》第10章复习题与编程练习

《C Primer Plus》第10章复习题与编程练习

ProgramNovice的博客 1144

(秋招复习)一些SLAM基础

秋招复习--SLAM基础知识篇

weixin_45432823的博客 770

《C Primer Plus》编程练习—第16章

C Primers Plus 第16章编程练习

chaofeng426的博客 2803

Spring Boot 调用豆包大模型如何开启联网搜索?

场景推荐方案有权限创建 Bot + 需强集成✅ 使用bot-xxxx无 Bot 权限 / 追求通用性✅ 自行集成搜索引擎 + 普通豆包模型仅需基础对话❌ 无需考虑联网豆包大模型确实支持联网搜索,但前提是:你用的是“智能体 Bot”,且它被配置了“网页搜索”插件,并调用正确的 API 端点。希望本文能帮你少走弯路,快速构建出真正“知天下事”的智能助手!

lpfasd123的博客 1129

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

《C Primer Plus》第7章复习题与编程练习

《C Primer Plus》第7章复习题与编程练习

ProgramNovice的博客 1157

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

C Primer Plus (中文版)第11章编程练习 参考答案(仅供参考~)

C Primer Plus (中文版)第11章编程练习 参考答案(仅供参考~)

成为富婆,报效祖国!! 2024

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

C Primer Plus 第六章 复习题&编程练习 答案

第六章 复习题&编程练习1. 写出执行完下列各行后quack的值是多少。后5行中使用的是前一行生成的quack的值。2. 假设value是int类型,下面循环的输出是什么?如果value是double类型,会出现什么问题?3. 用代码表示以下测试条件:4. 用代码表示以下测试条件:5. 下面的程序有点问题,请找出问题所在。6. 编写一个程序打印下面的图案,要求使用嵌套循环:7. 下面的程...

May21☀️ 4643

《C Primer Plus》(第6版)

《C Primer Plus》(第6版)

ProgramNovice的博客 1万+

《C Primer Plus》第 3 章复习题和编程练习

《C Primer Plus》第 3 章复习题和编程练习

潇雪的博客 1176

C Primer Plus 第五章 复习题&编程练习 答案

第五章 复习题&编程练习复习题1. 假设所有变量的类型都是int,下列各项变量的值是多少:2. 假设所有变量的类型都是int,下列各项变量的值是多少:3. 对下列各表达式求值:4. 请找出下面的程序中的错误。5. 这是程序清单 5.9 的另一个版本。从表面上看,该程序只使用了一条scanf()语句,比程序清单5.9简单。请找出不如原版之处。6. 下面的程序将打印出什么内容?7. 下面的程...

May21☀️ 3925

《C Primer Plus》第6章复习题与编程练习

《C Primer Plus》第6章复习题与编程练习

ProgramNovice的博客 696

C Primer Plus 第6版 编程练习——第16章

另外,如果你的实现有time()(第12章讨论过)或类似的函数,可任srand()中使用这个函数的输出来初始化随机数生成器 rand()。int类型的参数指定了动态数组中的元素个数,double 类型的值用于初始化元素(第1个值赋给第1个元素,以此类推)。直角坐标用向量的x轴和y轴的坐标来描述该向量。2.两数的调和平均数这样计算:先得到两数的倒数,然后计算两个倒数的平均值,最后取计算结果的倒数。需要一个函数来完成转换,该函数接受一个包含极坐标的结构,并返回一个包含直角坐标的结构(或返回指向该结构的指针)。

geesehoward20000的博客 993

《C Primer Plus》编程练习—第11章

第11章练习

chaofeng426的博客 726

《C Primer Plus》(第六版)第三章:数据和C|复习题与编程练习答案参考

原因2:int在不同系统有可能是16位,也可能是32位,而long类型在C标准下保证至少是32位,如果确实需要32位整数,应用long类型,以便把程序移植到16位机后仍然可以正常工作(C99中推荐使用int32_t / int64_t(定义于<stdint.h>)明确位宽,替代原生int / long)。转换过程中,每一步的计算都可能产生小数,例如,1杯等于0.5品脱,如果输入1杯,用整数的话品脱数会是0,而用浮点数则是0.5,更准确。编写一个程序,读取一个浮点数,先打印成小数点形式,再打印成指数形式。

Lown_1的博客 1642

《C Primer Plus》(第六版)第七章:C控制语句:分支和跳转|复习题与编程练习答案参考

编写一个程序,在循环中用switch语句实现用户输入不同的字母时有不同的响应,即输入a的响应是让用户输入洋蓟的磅数,b是甜菜的磅数,c是胡萝卜的磅数,q是退出订购。随后,程序应显示所有的购买信息:物品售价、订购的重量(单位:磅)、订购的蔬菜费用、订单的总费用、折扣(如果有的话)、运费和包装费,以及所有的费用总额。如果输入 1~5 以外的数字,程序应提醒用户输入正确的选项,然后再重复显示菜单提示用户输入。程序要记录累计的重量。即,如果用户输入 4 磅的甜菜,然后输入 5磅的甜菜,程序应报告9磅的甜菜。

Lown_1的博客 1112
上一篇: 【《C Primer Plus》读书笔记】第16章:C预处理器和C库
下一篇: 【《C Primer Plus》读书笔记】第17章:高级数据表示
UestcXiye
博客等级 码龄8年 9044粉丝 1306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址