c语言嵌套循环依次返回值,090815c语言学习日记(嵌套循环,数组输入读取,函数返回值,第六章)...

#include//嵌套循环

int main(){

const int ROWS=6;

const int C=6;

int row;

char ch;

for(row=0;row

{

for(ch=('A'+row);ch

printf("%c",ch);

printf("/n");

}

getch();

return 0;

}

#include//10个数求平均 ,数组在for的用法

int main()

{

const int SIZE=10;

int index,num[SIZE];

int sum=0;//注意这里,sum=0

float average;

printf("请输入10个分数:");

for(index=0;index

scanf("%d",&num[index]);

printf("这几个数分别是/n");

for(index=0;index

printf("%5d",num[index]);

printf("/n");

for(index=0;index

sum+=num[index];//先加index

average=(float)sum/SIZE;//强制数组转换

printf("平均数为:%.3f/n" ,average);

getch();

return 0;

}

#include//函数返回值

double power(double n,int p);

int main(){

double x,xpow;

int exp;

printf("Please enter a pair of numbers or q to quit/n");

while(scanf("%lf%d",&x,&exp)==2)

{

xpow=power(x,exp);

printf("%.3g to the power %d is %.5g/n",x,exp,xpow);

printf("please entet next pair of numbers or q to quit/n");

}

printf("hope you enjoyed this power trip/n");

getch();

return 0;

}

double power(double n,int p){

double pow=1;

int i;

for(i=1;i<=p;i++)

pow*=n;

return pow;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值