# 第一次

6-1

1.设计思路

2.流程图

3.实验代码

#include <stdio.h>

void splitfloat( float x, int *intpart, float *fracpart );

int main()
{
float x, fracpart;
int intpart;

scanf("%f", &x);
splitfloat(x, &intpart, &fracpart);
printf("The integer part is %d\n", intpart);
printf("The fractional part is %g\n", fracpart);

return 0;
}
void splitfloat( float x, int *intpart, float *fracpart )
{
int a;
float b;
a=x/1;
b=x-a;
*intpart=a;
*fracpart=b;
} 

6-2

1 设计思路

2.流程图

3.实验代码

#include <stdio.h>
#define MAXN 10

int search( int list[], int n, int x );

int main()
{
int i, index, n, x;
int a[MAXN];

scanf("%d", &n);
for( i = 0; i < n; i++ )
scanf("%d", &a[i]);
scanf("%d", &x);
index = search( a, n, x );
if( index != -1 )
printf("index = %d\n", index);
else

return 0;
}
int search( int list[], int n, int x ){
for(int i=0;i<n;i++)
if(x==list[i])
return i;
return -1;
}

6-3

1.设计思路

2.流程图

3.实验代码

#include <stdio.h>
void sum_diff( float op1, float op2, float *psum, float *pdiff );
int main()
{
float a, b, sum, diff;
scanf("%f %f", &a, &b);
sum_diff(a, b, &sum, &diff);
printf("The sum is %.2f\nThe diff is %.2f\n", sum, diff);

return 0;
}
void sum_diff( float op1, float op2, float *psum, float *pdiff )
{
*psum=op1+op2;
*pdiff=op1-op2;
}

7-1

1.设计思路

2.流程图

3.实验代码

 #include<stdio.h>
int main()
{
void move(int [20],int,int);
int number[20],N,M,i;
scanf("%d %d",&N,&M);
for(i=0;i<N;i++)
scanf("%d",&number[i]);
move(number,N,M);
for(i=0;i<N;i++)
printf("%d ",number[i]);
printf("\n");
return 0;
}
void move(int array[20],int N,int M)
{
int *p,array_end;
array_end=*(array+N-1);
for(p=array+N-1;p>array;p--)
*p=*(p-1);
*array=array_end;
M--;
if(M>0) move(array,N,M);
}

posted @ 2018-04-07 16:23  刘瀚渤  阅读(143)  评论(0编辑  收藏  举报