亚洲一级免费看,特黄特色大片免费观看播放器,777毛片,久久久久国产一区二区三区四区,欧美三级一区二区,国产精品一区二区久久久久,人人澡人人草

c語(yǔ)言函數(shù)實(shí)習(xí)報(bào)告

時(shí)間:2022-08-03 13:23:52 實(shí)習(xí)報(bào)告 我要投稿
  • 相關(guān)推薦

c語(yǔ)言函數(shù)實(shí)習(xí)報(bào)告

程序設(shè)計(jì)(C語(yǔ)言)實(shí)驗(yàn)報(bào)告

c語(yǔ)言函數(shù)實(shí)習(xí)報(bào)告

實(shí)驗(yàn)?zāi)康?/p>

(1)掌握函數(shù)的定義方法,調(diào)用方法,參數(shù)說(shuō)明以及返回值;

(2)掌握實(shí)參與形參的對(duì)應(yīng)關(guān)系,一集參數(shù)之間的“值傳遞”的方式;

(3)掌握函數(shù)嵌套調(diào)用及遞歸調(diào)用的設(shè)計(jì)方法;

(4)在編寫(xiě)過(guò)程中加深理解函數(shù)調(diào)用的程序設(shè)計(jì)思想。

實(shí)驗(yàn)內(nèi)容

(1)編輯,編譯,運(yùn)行實(shí)驗(yàn)指導(dǎo)中的程序,并分析輸出結(jié)果

(2)編寫(xiě)一個(gè)函數(shù)primeNum(int x),功能是判別一個(gè)數(shù)是否是素?cái)?shù)。

(3)編寫(xiě)函數(shù)mulNum(int a,int b),功能是判定a是否是b的整數(shù)倍

實(shí)驗(yàn)1方法一:

源程序:

#include<stdio.h>

#include<math.h>

int computeNum(int x)

{

int sum ,a,b,c,d,e;

sum=0;

x=abs(x);

a=x/10000;

b=(x%10000)/1000;

c=(x%1000)/100;

d=(x%100)/10;

e=(x%10)/1;

sum=a+b+c+d+e;

return sum;

}

main()

{

int a,b;

printf("Please input an integer:");

scanf("%d",&a);

b=computeNum(a);

printf("the sum of all digits is %d\n",b);

}

輸入一個(gè)整數(shù)123 運(yùn)行結(jié)果如圖

輸入整數(shù)98341驗(yàn)證 運(yùn)行結(jié)果如圖

方法二:

#include<stdio.h>

#include<math.h>

int computeNum(int x)

{

int sum,i,t;

sum=0;

x=abs(x);

for(i=4;i>=0;i--)

{

t=pow(10,i);

if(x>=t)

{

sum=sum+x/t;

x=x-(x/t)*t;

}

}

return sum;

}

main()

{

int a,b;

printf("Please input an integer:");

scanf("%d",&a);

b=computeNum(a);

printf("The sum of all digits is %d\n:",b); }

輸入整數(shù)456運(yùn)行結(jié)果如圖

輸入整數(shù)98341驗(yàn)證運(yùn)行結(jié)果如圖

實(shí)驗(yàn)2:

源程序:

#include<stdio.h>

void move(char geton ,char puton)

{

printf("%c->%c\n",geton,puton);

}

void Hanoi(int n,char one,char two,char three) {

if (n==1)

move(one,three);

else

{

Hanoi(n-1,one,three,two);

move(one,three);

Hanoi(n-1,two,one,three);

}

}

void main()

{

int m ;

printf("Input the number of diskes:"); scanf("%d",&m);

printf("The steps of moving %d diskes:\n",m); Hanoi(m,'A','B','C');

}

輸入3運(yùn)行結(jié)果如下:

輸入4運(yùn)行結(jié)果如下:

實(shí)驗(yàn)2:

源程序:

#include<stdio.h>

int i,a,x;

int primeNum(int x)

{

for(i=2;i<x;i++)

{

a=x%i;

if(a==0)

return 0;

}

return 1;

}

main()

{

printf("Please input x!\n");

scanf("%d",&x);

if(x<2)

printf("wrong in put!\n");

else

{

a=primeNum(x);

if(a==0)

printf("%d is not a prime number!\n",x); else

printf("%d is a prime number!\n",x);

}

}

輸入數(shù)據(jù)0運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)1運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)2運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)3運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)9運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)13運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)59運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)121運(yùn)行結(jié)果如下:

實(shí)驗(yàn)3: 源程序:

#include<stdio.h>

int mulNum(int a,int b) {

int i,c; c=a%b; if(c>0)

i=0; else i=1; return i; }

main() {

int a,b,s;

printf("please input a and b:\n"); scanf("%d %d",&a,&b); s=mulNum(a,b); if(s==1)

printf("%d is a multiple of %d\n",a,b); else

printf("%d is not a multiple of %d\n",a,b); }

輸入數(shù)據(jù)1和5運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)5和5運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)6和2運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)6和4運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)20和4運(yùn)行結(jié)果如下:

輸入數(shù)據(jù)37和9運(yùn)行結(jié)果如下:

出現(xiàn)的問(wèn)題及解決方法:

編譯過(guò)程中常出現(xiàn)因錯(cuò)漏而使語(yǔ)句不規(guī)范的現(xiàn)象。解決方法:更加認(rèn)真以及注意檢查。

實(shí)驗(yàn)心得:

通過(guò)本次試驗(yàn)我掌握了函數(shù)的定義,調(diào)用方法,參數(shù)的說(shuō)明以及返回值,函數(shù)遞歸調(diào)用的設(shè)計(jì)方法等,逐步理解了函數(shù)調(diào)用的程序設(shè)計(jì)思想,學(xué)習(xí)過(guò)程常會(huì)遇到問(wèn)題,因此需要認(rèn)真理解,多作練習(xí)。

【c語(yǔ)言函數(shù)實(shí)習(xí)報(bào)告】相關(guān)文章:

C語(yǔ)言函數(shù)的定義03-03

什么是C語(yǔ)言函數(shù)02-28

C語(yǔ)言常用的輸入函數(shù)03-04

C語(yǔ)言的函數(shù)分類03-24

c語(yǔ)言數(shù)學(xué)函數(shù)的介紹10-20

C語(yǔ)言中g(shù)ets()函數(shù)知識(shí)04-02

C語(yǔ)言函數(shù)調(diào)用與參數(shù)傳遞10-10

C語(yǔ)言函數(shù)參數(shù)傳遞問(wèn)題03-22

c語(yǔ)言隨機(jī)數(shù)生成函數(shù)和時(shí)間函數(shù)03-16

C語(yǔ)言中函數(shù)的區(qū)分有哪些04-27