
// this is a code calculating s=1/2+1/3+1/4+...+1/n=1 #include(2)计算浮点类型数的正整数次方int main() { int n,m; double s,d; printf("enter the number of loop:"); scanf("%d",&n); for (s=0,m=1,d=2;m<=n;m+=1,d*=2) { s+=1/d; printf("when loop =%d,d=%f,s=%fn ",m,d,s); } return 0; }
// this is a code calculating the positive power of a number #includefloat power(float n,int p); int main() { float di; int zhi; printf("please enter the dishiu and the zhisu(char or negtive number to quit"); while(scanf("%f%d",&di,&zhi)==2&&zhi>0) { printf("%f to the %dth power is %fn",di,zhi,power(di,zhi)); printf("please enter another group of number(char or negtive number to quit)"); } printf("quit successfullyn"); } float power(float n,int p) { int i; float pow=1; for(i=1;i<=p;i++) pow*=n; return pow; }
(3)ABA型金字塔
#includeint main() { char CH;int CHn; printf("please enter a character between A-Z"); CH=getchar();CHn=(int)CH-64; // CHn确定程序有多少行,用于第一个for循环 int hang,lie; for(hang=1,lie=1;hang<=CHn;hang++,lie=hang) { for( ;lie (4)输入字符串,倒序输出字符串.此时要注意,字符串的最后一个单元储存‘',所以定义时要注意单元总个数.
#include#include int main() { char lstring [100]; int n; printf("please enter a string:(within 100 characters):"); scanf("%s",lstring); n=strlen(lstring); int a;char string[n]; for(a=0;a 欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)