首页 > 编程知识 正文

101路公交车路线,10102368是什么电话

时间:2023-05-03 13:19:35 阅读:267465 作者:2586

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: %dn",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: %ldn", t);}

要点: 排序(冒泡)

详细代码如下:

#include <stdio.h>#define N 16typedef 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) ;}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。