5-1
#include<stdio.h> int main(void) { double height,radius,volume; double cylinder(double r,double h); printf("Enter radius and height:"); scanf("%lf%lf",&radius,&height); volume=cylinder(radius,height); printf("Volume=%.3f ",volume); return 0; } double cylinder(double r,double h) { double result; result=3.1415926*r*r*h; return result; }
5-3
#include<stdio.h> #include<math.h> int main(void) { double e,pi; double funpi(double e); printf("Enter e:"); scanf("%lf",&e); pi=funpi(e); printf("pi=%f ",pi); return 0; } double funpi(double e) { int denominator,flag; double item,sum; flag=1; denominator=1; item=1.0; sum=0; while(fabs(item)>=e){ item=flag*1.0/denominator; sum=sum+item; flag=-flag; denominator=denominator+2; } return sum*4; }
5-4
#include<stdio.h> #include<math.h> int main(void) { int count,m; int prime(int m); count=0; for(m=2;m<=100;m++){ if(prime(m)!=0){ printf("%6d",m); count++; if(count%10==0) printf(" "); } } printf(" "); }