#include<stdio.h>#include<string.h>voidtranslation(){int n;char num[40];char eng[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};printf("input a number:");scanf("%s",&num);
n =strlen(num);for(int i =0; i < n; i++){printf("%c", num[i]);}if(n ==0){printf("input error");}else{printf("翻译是:%s", eng[num[0]-48]);for(int i =1; i <= n -1; i++){printf("-%s", eng[num[i]-48]);}}}voidmain(){translation();}
例题2(找钱)
#include<stdio.h>//x元的商品,给了y元voidchange(int x,int y){int money[7]={0,50,20,10,5,2,1}, s[7]={0};int balance;int num;
balance = y - x;for(int i =1; i <=6; i++){//6种钱
num = balance / money[i];
s[i]= num;
balance -= num * money[i];}for(int i =1; i <=6; i++){if(s[i]!=0){printf("%d元----%d张\n", money[i], s[i]);}}}voidmain(){change(46,100);}
3.数组记录状态信息
例题1(求满足要求的x)
#include<stdio.h>voidqiuX(){long x, y1, y2;int p[10], t, k;for(int x =10000; x <32000; x++){for(int i =0; i <10; i++){
p[i]=1;}
y1 = x * x;
y2 = y1;
k =0;for(int i =0; i <10; i++){
t = y2 %10;
y2 /=10;if(p[t]=1){
k++;
p[t]=0;}else{break;}}if(k ==9){printf("%d\n", x);}}}voidmain(){qiuX();}
#include<stdio.h>#include<string.h>voidhighPrecision(){long b, c, d;int a[256], n, i, j;char s[256];printf("输入高精度数字:");scanf("%s",&s);printf("输入相乘的数:");scanf("%ld",&c);
n =strlen(s);
d =0;for(i =0, j = n -1; i < n; i++, j--){
b =(s[j]-48)* c + d;//b来计算每一位。最后一位 * c + 进位
a[i]= b %10;//因为是10进制,才对10求余
d = b /10;//b剩下的作为进位}while(d !=0){//最后的进位(可能大)(按位来)
a[n]= d %10;
d = d /10;
n++;}for(i = n -1; i >=0; i--){printf("%d", a[i]);}}voidmain(){highPrecision();}
#include<stdio.h>#include<string.h>voidhighPrecision(){int i, j, r =1;long a[256], b, d;int m =1;//m是结果的位数,一开始只有一个1,结果只有1位int n;printf("n!中的n:");scanf("%d",&n);for(i =0; i <256; i++){
a[i]=0;}
a[1]=1;//运算
d =0;for(i =2; i <= n; i++){//n-1个数,一个一个来for(j =1; j <= m; j++){
b =(a[j]* i)+ d;
a[j]= b %1000000;//10e6进制,倒存入a
d = b /1000000;}if(d !=0){
a[j]= d;
m++;}}/*
//找到!=的最后一个
for (i = m; i >= 1; i--) {
if (a[i] != 0) {
continue;
}else {
r = i;
break;
}
}
*/
r = m;printf("n! = ");printf("%ld ", a[r]);for(i = r -1; i >=1; i--){if(a[i]>99999){printf("%d ", a[i]);continue;}elseif(a[i]>9999){printf("0%d ", a[i]);continue;}elseif(a[i]>999){printf("00%d ", a[i]);continue;}elseif(a[i]>99){printf("000%d ", a[i]);continue;}elseif(a[i]>9){printf("0000%d ", a[i]);continue;}else{printf("00000%d ", a[i]);continue;}}}voidmain(){highPrecision();}