#include<stdio.h> int sum=0; int OddSum(int n) { if(n%2) sum+=n; return sum; } int main() { int num,n,i,result; printf("输入n:"); scanf("%d",&n); printf("依次输入每个值并用空格隔开\n"); for(i=0;i<n;i++) { scanf("%d",&num); result=OddSum(num); } printf("%d所有的奇数和为%d\n",n,result); return 0; }
复制代码 #include<stdio.h> double mypow(double x,int n) { double t=1; int i; for(i=0;i<n;i++) t=t*x; return t; } int main() { double x,result; int n; printf("请输入底数x:"); scanf("%lf",&x); printf("请输入指数n:"); scanf("%d",&n); result=mypow(x,n); printf("结果为%lf",result); }
#include<stdio.h> double cylinder(double r,double height) { double v; v=3.14*r*r*height; return v; } int main() { double result,r,height; printf("请输入半径r:"); scanf("%lf",&r); printf("请输入高height:"); scanf("%lf",&height); result=cylinder(r,height); printf("体积为%lf",result); return 0; }
时间: 2024-11-05 19:27:17