1、二 2.1 #include void main() /本题原考虑 在 16 位机器上 实验目前多为 32 位机器故已过时。 int a = 42486; cout #include const double pi = 3.1415926; void main() double radius1, radius2; cout radius1 radius2; cout #include const double e = 2.718281828; void main() cout void main() cout void main() cout #include #include #includ
2、e void main() float a,b,c,s,area; /printf(“please input 3 sides of one triangle:n“); cout a b c; /输入时以空格作 为数据间隔 s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c); /printf(“a=%7.2f,b=%7.2f,c=%7.2fn“,a,b,c); cout #include #include float area(float a, float b, float c); /函数声明 void main() float a,b,c; cout a b
3、 c; /输入时以空格作 为数据间隔 float result = area(a,b,c); /函数调用 cout #include double Cylinder(double r, double h); void main() double radius, height; cout radius height; double volume = Cylinder(radius, height); cout void main() int x; cout x; if(x-1 cout a; int c1 = a%3 =0; int c2 = a%5 =0; int c3 = a%7 =0; s
4、witch(c1 void main() int grade; cout grade; if(grade100|grade=90) cout =80) cout =70) cout =60) cout #include void main() double sum=1, t=-1, x; int i=1; cout x; do t*=(-1)*x/i; sum+=t; i+; while(fabs(t)1e-8); cout #include void main() double sum=1, t=-1, x; cout x; int i=1; while(fabs(t)1e-8) t*=(-
5、1)*x/i; sum+=t; i+; cout #include void main() double sum=1, t=-1, x; cout x; for(int i=1; fabs(t)1e-8; i+) t*=(-1)*x/i; sum+=t; cout void main() long sum=0, t=1; for(int i=1; i void main() for(int i=1; i void main() for(int i=1; i void main() float s=100,h=100; for(int i=1; i void main() int peachs=
6、1; for(int i=1; i #include void main() double x, a; cout a; x = a/2; while(fabs(x-a/x)/2)1e-7) x=(x+a/x)/2; cout void main() for(int i=1; i void main() for(int i=1; i #include void main() cout #include void main() cout #include void main() cout void main() int n; long a=1, b=1, c=1, temp; cout n; fo
7、r(int i=4; i #include #include bool isprime(long n); void main() /input long a,b,l=0; cout a b; cout #include #include double f(double x); double integral(double a, double b); const double eps = 1e-8; void main() double a=0, b=1; cout =eps) tn = t2n; in = i2n; double sigma = 0.0; for(int k=0; k #inc
8、lude void multab1(); void multab2(); void multab3(); void main() multab1(); multab2(); multab3(); void multab1() cout void main() int n; long a=1, b=1, temp; cout n; for(int i=3; i #include void main() double x, y; x = 3.14159/4; do y = x; /x-=(cos(x)-x)/(sin(x)-1); x = cos(x); while(fabs(x-y)1e-6);
9、 cout void display(double d) cout long cattle(int n); void main() int n; cout n; cout #include void multab1(); void multab2(); void multab3(); 七 7.1 #include int findMinIndex(int a, int n); void main() int array=34,91,83,56,29,93,56,12,88,72; int size=sizeof(array)/sizeof(*array); int minIndex = fin
10、dMinIndex(array, size); cout ai) index = i; return index; 7.2 #include int insert(int a, int n, int value); void main() int array=12,29,34,56,72,83,88,91; int size=sizeof(array)/sizeof(*array); cout aValue; int max=insert(array,size,aValue); cout =0 i-) ai+1=ai; ai+1=value; return retValue; 7.3 #inc
11、lude const int num=17; void main() int interval=3; int anum; for(int i=0; iai+1) dontLoopAgain=false; Swap(ai,ai+1); 7.5 #include const int n=5; int sum(int a5, int size); void main() int arraynn=3,2,4,1,5, 8,7,2,5,6, 6,9,1,4,3, 5,5,3,6,2, 2,8,1,8,6; cout void findMax(int a4, int row,int col); void
12、findBad(int a4, int row,int col); void average(int a4, int row,int col); void main() int array54=88,67,48,91, 61,65,37,77, 92,81,73,60, 51,55,60,60, 77,63,70,80; findMax(array,5,4); findBad(array,5,4); average(array,5,4); void findMax(int a4, int row,int col) int r=0,c=0; for(int i=0; iarc) r=i,c=j;
13、 cout int a33=5,7,8,2,-2,4,1,1,1; int b33=4,-2,3,3,9,4,8,-1,2; int c33; void main() for(int i=0; i int* findmax(int* array, int size, int* index); void main() int a10=33,91,54,67,82,37,85,63,19,68; int* maxaddr; int idx; maxaddr=findmax(a, sizeof(a)/sizeof(*a), cout array*index) *index=i; return 8.2
14、 #include bool assign(); int num,interval; void main() if(!assign() return; int* a=new intnum; for(int i=0; inum interval; if(num1 switch(sele) case 1: return false; case 2: sign=false; break; case 3: num=10; interval=3; return true; /end of switch /end of inner while /end of out while 8.3 #include
15、#include int CompIntBitSum(const void* a, const void* b); int CompFloat(const void* a, const void* b); int CompStrLen(const void* a, const void* b); void main() int a=12,32,42,51,8,16,21,19,9; int anum=sizeof(a)/sizeof(*a); cout char* jiami(const char* str); char* jiemi(const char* str); const char
16、key=4,9,6,2,8,7,3; const keylen=sizeof(key); void main() char* s=“the result of 3 and 2 is not 8“; cout 122) resulti-=90; return result; char* jiemi(const char* str) int len=strlen(str); char* result = new charlen+1; for(int i=0,j=0; i int strcmp(const char* str1, const char* str2); void main(int ar
17、gc, char*argv) if(argc!=3) cout 8_7 string1 string2n“; return; int result = strcmp(argv1,argv2); char c=; if(result0) c=; if(result #include #include void transpose(int* a, int size); /降维处理 void main() int A55; randomize(); for(int i=0; i #include void main() void* p = malloc(1000000); int i=1; whil
18、e(p) p = malloc(1000000); i+; cout const size=10; void findmax(int* a, int n, int i, int void main() int asize; int n=0; cout ai; findmax(a, size, 0, n); cout apk) pk=i; findmax(a,n,i+1, (2) /求数 组中最大元素的下标,放入主函数的变量 n 中. (3) #include const size=10; void findmax(int* a, int n, int void main() int asize
19、; int n=0; cout ai; findmax(a,size,n); cout apk) pk=i; 9_2 #include #include int /put value into the array int get(int n); /obtain a value from the arrayint vals10; int error=-1; void main() put(0)=10; /put values into the array put(1)=20; /. put(9)=30; cout =10) cerr =10) cerr void Swap(char* void
20、main() char* ap=“hello“; char* bp=“how are you?“; cout struct Student int mathmidterm; int mathfinal; ; void main() Student s; cout s.mathmidterm s.mathfinal; cout #include struct Node char str20; Node* next; ; void Insert(Node* void main() Node* p; Node* x=new Node; strncpy(x-str,“hello“,20); x-nex
21、t = NULL; p =x; x=new Node; strncpy(x-str,“jone“,20); x-next = p; p=x; x=new Node; strncpy(x-str,“good“,20); x-next = p; p=x; x=new Node; strncpy(x-str,“better“,20); x-next = p; p=x; cout next) cout str “; cout next) cout str “; cout str,“marit“,20); head-str19=0; if(!head) head = p; p-next = NULL; return; if(!strcmp(head-str, “jone“) p-next = head; head = p; return; Node* sp;