沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx

上传人:b****4 文档编号:6479546 上传时间:2023-05-06 格式:DOCX 页数:22 大小:18.18KB
下载 相关 举报
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第1页
第1页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第2页
第2页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第3页
第3页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第4页
第4页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第5页
第5页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第6页
第6页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第7页
第7页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第8页
第8页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第9页
第9页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第10页
第10页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第11页
第11页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第12页
第12页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第13页
第13页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第14页
第14页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第15页
第15页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第16页
第16页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第17页
第17页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第18页
第18页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第19页
第19页 / 共22页
沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx

《沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx》由会员分享,可在线阅读,更多相关《沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx(22页珍藏版)》请在冰点文库上搜索。

沈阳建筑大学C语言知识学习深刻复习资料Word文档格式.docx

for(i=1;

i<

=101;

i=i+2)

{

sum=sum+i;

}

printf("

sum=%d\n"

sum);

}

(2)

inti=1,sum=0;

while(i<

=101)

i=i+2;

math.h>

inti1,i2,i3,i4,k,n;

Inputdatais:

"

);

scanf("

%d"

&

n);

k=fabs(n);

/*取绝对值*/

i1=k/1000;

/*分离出千位*/

i2=(k-i1*1000)/100;

/*分离出百位*/

i3=(k-i1*1000-i2*100)/10;

/*分离出十位*/

i4=k%10;

/*分离出个位*/

Thesumofthetotalbitis%d\n"

i1+i2+i3+i4);

intx,y,z;

for(x=0;

x<

=20;

x++)

for(y=0;

y<

=33;

y++)

{

z=100-x-y;

if(5*x+3*y+z/3.0==100)

{

printf("

x=%d,y=%d,z=%d\n"

x,y,z);

}

}

5.4

(1)

intn,ret;

Inputn:

&

ret=IsPrimeNumber(n);

if(ret!

=0)

printf("

%disaprimenumber\n"

n);

else

%disnotaprimenumber\n"

/*

函数功能:

判断参数是否是素数

函数入口参数:

number为整型数,要求为正整数

函数返回值:

非0值表示是素数,否则不是素数

*/

intIsPrimeNumber(intnumber)

inti;

if(number<

=1)/*负数、0和1都不是素数*/

return0;

for(i=2;

i<

=sqrt(number);

i++)

if((number%i)==0)/*被整除,不是素数*/

return0;

return1;

inti,flag=1;

/*标志变量置为真,假设是素数*/

flag=0;

flag=0;

returnflag;

intMinCommonMultiple(inta,intb);

inta,b,x;

Inputa,b:

%d,%d"

a,&

b);

x=MinCommonMultiple(a,b);

MinCommonMultiple=%d\n"

x);

计算两个正整数的最小公倍数

两个整型数

最小公倍数

intMinCommonMultiple(inta,intb)

for(i=1;

b;

if((i*a)%b==0)

returni*a;

returnb*a;

intMaxCommonFactor(inta,intb);

x=MaxCommonFactor(a,b);

MaxCommonFactor=%d\n"

计算两个正整数的最大公约数

最大公约数

intMaxCommonFactor(inta,intb)

intr;

do{

r=a%b;

a=b;

b=r;

}while(r!

=0);

returna;

inta[10],n,max,min,maxPos,minPos;

for(n=0;

n<

10;

n++)

scanf("

a[n]);

max=min=a[0];

maxPos=minPos=0;

if(a[n]>

max)

{

max=a[n];

maxPos=n;

elseif(a[n]<

min)

min=a[n];

minPos=n;

max=%d,pos=%d\n"

max,maxPos);

min=%d,pos=%d\n"

min,minPos);

#defineARR_SIZE10

函数功能:

找出n个数中的最大数与最小数并将其位置对换

函数参数:

整型数组a,存放待处理数据

整型变量n,为数据个数

返回值:

voidMaxMinExchang(inta[],intn)

intmaxValue=a[0],minValue=a[0],maxPos=0,minPos=0;

inti,temp;

n;

if(a[i]>

maxValue)

maxValue=a[i];

maxPos=i;

if(a[i]<

minValue)

minValue=a[i];

minPos=i;

temp=a[maxPos];

a[maxPos]=a[minPos];

a[minPos]=temp;

inta[ARR_SIZE],i,n;

Inputn(n<

=10):

n);

Input%dNumbers:

\n"

n);

for(i=0;

a[i]);

MaxMinExchang(a,n);

AfterMaxMinExchange:

for(i=0;

%4d"

a[i]);

);

string.h>

#defineARR_SIZE80

charstr[ARR_SIZE];

intlen,i,letter=0,digit=0,space=0,others=0;

Pleaseinputastring:

gets(str);

str[i]!

='

\0'

;

if(str[i]>

a'

&

&

str[i]<

z'

||str[i]>

A'

Z'

letter++;

/*统计英文字符*/

elseif(str[i]>

='

0'

str[i]<

9'

digit++;

/*统计数字字符*/

elseif(str[i]=='

'

space++;

/*统计空格*/

others++;

/*统计其他字符的个数*/

Englishcharacter:

%d\n"

letter);

digitcharacter:

digit);

space:

space);

othercharacter:

others);

7.6

(1)

intFindMax(intnum[],intn,int*pMaxPos);

intFindMin(intnum[],intn,int*pMinPos);

intnum[10],maxValue,maxPos,minValue,minPos,i;

Input10numbers:

\n"

num[i]);

/*输入10个数*/

maxValue=FindMax(num,10,&

maxPos);

/*找最大值及其所在下标位置*/

minValue=FindMin(num,10,&

minPos);

/*找最小值及其所在下标位置*/

Max=%d,Position=%d,Min=%d,Position=%d\n"

maxValue,maxPos,minValue,minPos);

/*函数功能:

求n个数中的最大值及其所在下标位置

整型数组num,存储n个整数

整型变量n,表示数组元素个数

函数出口参数:

整型指针变量pMaxPos,指向的地址单元存储最大值在数组中的下标位置

最大值

intFindMax(intnum[],intn,int*pMaxPos)

inti,max;

max=num[0];

/*假设num[0]为最大*/

*pMaxPos=0;

/*假设最大值在数组中的下标位置为0*/

n;

if(num[i]>

max=num[i];

*pMaxPos=i;

returnmax;

求n个数中的最小值及其所在下标位置

函数入口参数:

函数出口参数:

整型指针变量pMinPos,指向的地址单元存储最小值在数组中的下标位置

最小值

intFindMin(intnum[],intn,int*pMinPos)

inti,min;

min=num[0];

/*假设num[0]为最小*/

*pMinPos=0;

/*假设最小值在数组中的下标位置为0*/

i<

10;

i++)

if(num[i]<

min=num[i];

*pMinPos=i;

returnmin;

voidFindMax(intnum[],intn,int*pMax,int*pMaxPos);

voidFindMin(intnum[],intn,int*pMin,int*pMinPos);

/*输入10个数*/

FindMax(num,10,&

maxValue,&

FindMin(num,10,&

minValue,&

整型指针变量pMax,指向的地址单元存储最大值

voidFindMax(intnum[],intn,int*pMax,int*pMaxPos)

*pMax=num[0];

*pMax)

*pMax=num[i];

整型指针变量pMin,指向的地址单元存储最小值

voidFindMin(intnum[],intn,int*pMin,int*pMinPos)

*pMin=num[0];

*pMin)

*pMin=num[i];

(3)

voidFindMaxMin(intnum[],intn,int*pMax,int*pMaxPos,int*pMin,

int*pMinPos);

scanf("

/*找最大值最小值及其所在下标位置*/

FindMaxMin(num,10,&

maxPos,&

求n个数中的最大值和最小值及其所在下标位置

整型指针变量pMinPos,指向的地址单元存储最小值在数组中的下标位置

int*pMinPos)

*pMin=num[0];

/*假设num[0]为最小*/

/*假设最小值在数组中的下标位置为0*/

elseif(num[i]<

7.8

(1)

voidInverse(char*pStr);

charstr[80];

Inputastring:

gets(str);

/*输入字符串*/

Inverse(str);

/*将存于str数组中的字符串逆序存放*/

Theinversedstringis:

puts(str);

/*输出字符串*/

/*函数功能:

实现字符串逆序存放

函数参数:

字符指针变量,所指向的存储单元存放源字符串,逆序后的字符串也存放于此

voidInverse(char*pStr)

intlen;

chartemp;

char*pStart;

/*指针变量pStart指向字符串的第一个字符*/

char*pEnd;

/*指针变量pEnd指向字符串的最后一个字符*/

len=strlen(pStr);

/*求出字符串长度*/

for(pStart=pStr,pEnd=pStr+len-1;

pStart<

pEnd;

pStart++,pEnd--)

temp=*pStart;

*pStart=*pEnd;

*pEnd=temp;

intlen=0;

char*pStart=pStr;

/*指针变量pStart指向字符串的第一个字符*/

/*指针变量pEnd指向字符串的最后一个字符*/

for(;

*pStart!

pStart++)len++;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2