76! 双f

76 date:2021.2.24
在这里插入图片描述

要点:

排序

详细代码如下:

#include   <conio.h>
#include   <stdio.h>
#define    N   20
/*************found**************/
void fun(int *a,int n)
{
    
    
 int  i,  m, t, k;
 for(i=0; i<n;i++)
   {
    
    
    /*************found**************/
    m=i;
    for(k=i+1; k<n; k++)
      if(a[k]>a[m])
         m=k;
    t=a[i];
    a[i]=a[m];
    a[m]=t;
   }
}
void main()
{
    
     
  int b[N]={
    
    11,5,12,0,3,6,9,7,10,8},n=10,i;
  system("CLS");
  for(i=0; i<n; i++)  
    printf("%d ",b[i]);
  printf("\n");
  fun(b,n);
  for(i=0; i<n; i++)  
    printf("%d ", b[i]);
  printf("\n");
}

在这里插入图片描述

要点:
思路:先确定位数—>再求10的n-1次方——> 求余

详细代码如下:

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
unsigned fun(unsigned w)
{
    
    
  /*
	analyse:

	w  返回w的后n - 1 位数字reutrn

	求 是几位数: 取出位数
  */
	int n =1 ,j ,s =1;  //注意初值的确定是1,不是0

	unsigned t;

	t = w;
	/*首先确定w的位数,用变量n保存*/

	while( t >= 10)
	{
    
    
		/*每次循环使s的位数减1 , 同时n加1*/
		t = t/10;
		n++;
	}

	/*求10 的n-1次方*/

	for(j = 1; j < n; j++)
		s = s * 10;

	//用w对10的n-1次方求余即可得到所求
	return w%s;

}
void main()
{
    
     
  FILE *wf;
  unsigned x;
  system("CLS");
  printf("Enter a unsigned integer number: ");
  scanf ("%u",&x);
  printf("The original data is:%u\n",x);
  if(x<10) 
    printf("Data error! ");
  else 
    printf ("The result :%u\n", fun(x));
/******************************/
  wf=fopen("out.dat","w");
  fprintf(wf,"%u",fun(5923));
  fclose(wf);
/*****************************/
}

猜你喜欢

转载自blog.csdn.net/weixin_44856544/article/details/114025481
76