78!

78 date:2021.2.25

在这里插入图片描述

要点:

详细代码如下:


#include    <stdio.h>
#include    <string.h>
#define    M    5
#define    N    20
void fun(char  (*ss)[N])
{
    
      int  i, j, k=0, n, m, len;
   for(i=0; i<M; i++)
   {
    
      len=strlen(ss[i]);
      if(i==0) n=len;
      if(len>n) {
    
    
/**********found**********/
         n=len;  k=i;
      }
   }
   for(i=0; i<M; i++)
    if (i!=k)
    {
    
     m=n;  //最长字符串长度赋值给m
      len=strlen(ss[i]);
/**********found**********/
      for(j=len; j>=0; j--)
         ss[i][m--]=ss[i][j];
      for(j=0; j<n-len; j++)
/**********found**********/
          ss[i][j]='*';
    }
}
void main()
{
    
      char  ss[M][N]={
    
    "shanghai","guangzhou","beijing","tianjing","cchongqing"};
   int  i;
   printf("\nThe original strings are :\n");
   for(i=0; i<M; i++)  printf("%s\n",ss[i]);
   printf("\n");
   fun(ss);
   printf("\nThe result:\n");
   for(i=0; i<M; i++)  printf("%s\n",ss[i]);
}


在这里插入图片描述

要点:
n的阶乘

详细代码如下:

#include  <stdlib.h>
#include  <stdio.h>
double fun(int n)
{
    
    
 double result=1.0;
 while(n>1&&n<170) 
/*************found**************/
      result*=n--;
/*************found**************/
 return result;
}
void main()
{
    
    int n;
 system("CLS");
 printf("Enter an integer: ");
 scanf("%d",&n);
 printf("\n\n%d!=%1g\n\n ",n,fun(n));
}

在这里插入图片描述

要点:
还算简单

详细代码如下:

#include <string.h>
#include <stdio.h>
void fun( char s[],int c)
{
    
    
  /*
	analyse:

	删除字符串中指定的字符
  */

	int i,j=0;

	for(i = 0; s[i] != '\0'; i++)
	{
    
    
		if(s[i] != c)
		{
    
    
			s[j] =s[i];
			j++;
		}
	}
	s[j] = '\0';
}
void main()
{
    
    
  static char str[]="turbo c and borland c++";
  char ch;
  FILE *out;
  printf ("原始字符串:%s\n ",str);
  printf("输入一个字符串:\n");
  scanf("%c",&ch);
  fun(str,ch);
  printf("str[]=%s\n",str);
  strcpy(str,"turbo c and borland c++");
  fun(str,'a');
  /******************************/
  out=fopen("out.dat","w");
  fprintf(out,"%s",str);
  fclose(out);
  /******************************/
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44856544/article/details/114108266
78
今日推荐