101

101 date:2021.2.10
在这里插入图片描述要点: 三位数数值各个位的表示方法,个位表示为n%10十位表示为n/10%10百位表示为n/100

详细代码如下:

#include  <stdio.h>
int fun(int  x)
{ int  n, s1, s2, s3, t;
  n=0;
  t=100;
/**********found**********/
  while(t<= 999){
/**********found**********/
    s1=t%10;  s2=(t/10)%10;  s3=t/100;
/**********found**********/
    if(s1+s2+s3== x)
    {  printf("%d ",t);
       n++;
    }
    t++;
  }
  return  n;
}
void main()
{ int x=-1;
  while(x<0)
  { printf("Please input(x>0): ");  scanf("%d",&x);  }
  printf("\nThe result is: %d\n",fun(x));
}


在这里插入图片描述要点:

详细代码如下:

#include <stdio.h>

/************found************/
void fun (long  s, long *t)
{   long  sl=10;
    s /= 10;
    *t = s % 10;
/************found************/
    while ( s > 0)//每循环一次就从s中的数上取出一位进行运算,直到取完为止
    {  s = s/100;
       *t = s%10*sl + *t;
       sl = sl * 10;
    }
}

void main()
{  long   s, t;
   printf("\nPlease enter s:"); scanf("%ld", &s);
   fun(s, &t);
   printf("The result is: %ld\n", t);
}


在这里插入图片描述要点: 排序(冒泡)

详细代码如下:

#include <stdio.h>
#define   N   16
typedef  struct
{  char  num[10];
   int   s;
} STREC;
void  fun( STREC  a[] )
{
	/*
		analyse:
		通过n-1次冒泡将n-1个学生存放到合适位置,最后一个不需要处理了,因为n-1个都处理完成了,最后一个也自然而然
	*/

	int i,j;
	STREC t;

	for(i = 0; i<N; i++) //用冒泡法进行排序,进行N-1次比较
		for(j = 0; j<N-1; j++)  //在每一次比较中要进行N-1次两两比较
			if(a[j].s < a[j+1].s)
			{
				t = a[j];
				a[j] = a[j+1];  /*按分数的高低排列学生的记录,高分在前*/
				a[j+1] = t;
			}
}

void main()
{  STREC  s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
		{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},
		{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
		{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};
   int  i;FILE *out ;
   fun( s );
   printf("The data after sorted :\n");
   for(i=0;i<N; i++)
   {  if( (i)%4==0 )printf("\n");
      printf("%s  %4d  ",s[i].num,s[i].s);
   }
   printf("\n");
   out = fopen("out.dat","w") ;
   for(i=0;i<N; i++)
   {  if( (i)%4==0 && i) fprintf(out, "\n");
      fprintf(out, "%4d  ",s[i].s);
   }
   fprintf(out,"\n");
   fclose(out) ;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值