37(删除字符串中指定下标字符,将剩余的字符存入b数组中 fabs()求绝对值)

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() ;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值