x的n次方
#include <stdio.h> double mypow(double x,int n) { int i; for(i=0;i<n;i++) mypow*=x; } int mian() { int i,n; double mypow=1.0,x; printf("输入x和n:"); scanf("%lf%d",&x,&n); mypow*=x; printf("%.2f ",mypow(double x,int n)); return 0; }
圆柱体积
#include<stdio.h> double cylinder(double r,double height) { double v; v=3.14*r*r*height; } int main() { double r,height,v; printf("请输入圆柱体的半径和高:") ; scanf("%lf %lf",&r,&height); v=3.14*r*r*height; cylinder(r,height); printf("圆柱体体积为:%lf",v); return 0; }
奇数和
#include<stdio.h> int OddSum(int x) { int sum=0; if(x%2==0) x=0; else sum=sum+x; return sum; } int main() { int i,n; printf("请输入n个数:"); scanf("%d",&x); for(i=0;i<=x;i++) printf("奇数和为:"); return 0; }