37 date:2021.3.22
要点:
详细代码如下:
#include <stdio.h>
void fun(char *s, char *p)
{ int i, j, n, x, t;
n=0;
for(i=0; s[i]!='\0'; i++) n++;
for(i=1; i<n-2; i=i+2) {
/**********found**********/
t = i; //将下标为奇数的字符赋值给中间变量t
/**********found**********/
for(j=i+2 ; j<n; j=j+2) //for循环实现对下标为奇数的元素进行排序
if(s[t]>s[j]) t=j;
if(t!=i)
{ x=s[i]; s[i]=s[t]; s[t]=x; }
}
for(i=1,j=0; i<n; i=i+2, j++) p[j]=s[i];
/**********found**********/
p[j]='\0';
}
void main()
{ char s[80]="baawrskjghzlicda", p[50];
printf("\nThe original string is : %s\n",s);
fun(s,p);
printf("\nThe result is : %s\n",p);
}
要点:
#include <math.h>下的 fabs()求绝对值函数
详细代码如下:
#include <math.h>
#include <stdio.h>
float fun ( float num )
{ int s ;
float n, t, pi ;
t = 1 ; pi = 0 ; n = 1 ; s = 1 ;
/**************found**************/
while(fabs(t) >= num) //绝对值fabs()
{
pi = pi + t ;
n = n + 2 ;
s = -s ;
/**************found**************/
t = s / n ;
}
pi = pi * 4 ;
return pi ;
}
void main( )
{ float n1, n2 ;
printf("Enter a float number: ") ;
scanf("%f", &n1) ;
n2 = fun(n1) ;
printf("%6.4f\n", n2) ;
}
要点:
详细代码如下:
#include <stdio.h>
#include <string.h>
#define LEN 20
void fun (char a[], char b[], int n)
{
/*
analyse:
遍历原字符串;
间接删除;
*/
int i,j=0;
for(i = 0; i<20; i++)
{
if(i != n )
b[j++] = a[i];
}
b[j] = '\0';
}
void main( )
{ char str1[LEN], str2[LEN] ;
int n ;
void NONO ( );
printf("Enter the string:\n") ;
gets(str1) ;
printf("Enter the position of the string deleted:") ;
scanf("%d", &n) ;
fun(str1, str2, n) ;
printf("The new string is: %s\n", str2) ;
NONO() ;
}