#includemain(){int n,i,s=0,sum=0;printf("请输入一个整数:");scanf("%d",&n);i=n;while(i!=0){s+=(i%10)*(i%10)*(i%10);i/=10;sum++;}printf("是%d位数,各位立方和为%d\n",sum,s);}结果一 题目 用C语言编写程序,输入一个任意整数,求它的位数及各位数字之立方和.【使用while语句】...
int i;void StepTwo(int x){ for(i=0;x!=0;i++,x/=10)printf("%d",x%10);} int StepOne(int x){ for(i=0;x!=0;i++,x/=10);return i;} void main(){ int x;puts("请输入整数:");scanf("%d",&x);printf("位数:%d",StepOne(x));printf("\n逆序输出:");StepTwo...
include <stdio.h>int main(){ int n; scanf ("%d", &n);//输入字 if (n == 0){ printf ("zero\n"); } else if (n == 1){//1 printf ("one\n"); } else if (n == 2){//2 printf ("two\n"); } else if (n == 3){//...
include<stdio.h>void showbit(int n){ if(n>1){ showbit(n/2); printf(" "); } printf("%d",n%2);}void showoct(int n){ if(n>7){ showoct(n/8); printf(" "); } printf("%d",n%8);}void showhex(int n){ if(n>15){ showh...
你的这个问题难点在于判断输入的数是多少位的。我这里运用了一个将数转换成字符数组(sprintf函数),然后用strlen函数算出这个int型的数有多少位。后面再利用一个字符数组来接收修改后的数,再由字符串转成数字就好。具体见代码。代码在linux系统下 gcc编译器下运行通过,结果如下。在vs下同样可以通过 ...
include <stdio.h>int main(void){ int num,i; printf("Enter a number:"); scanf("%d",&num); i=num; while(i/10) i=i/10; printf("最高位是:%d\t最低位是:%d\n",i,num%10); return 0;} ...
include<stdio.h>main(){int x;char English[6][10]={"zero","one","two","three","four","five"};printf("输入任意一个数字:");scanf("%d",&x);if (x>=0&&x<=5) printf("%s\n",English[x]);else printf("error\n");} ...
include<stdio.h> main(){ int n,i,s=0,sum=0;printf("请输入一个整数:");scanf("%d",&n);i=n;while(i!=0){ s+=(i%10)*(i%10)*(i%10);i/=10;sum++;} printf("是%d位数,各位立方和为%d\n",sum,s);}
include <stdio.h> include <stdlib.h> int sum(int a){ if(!a)return 0;int cout = a%10;return cout + sum(a/10);} int main(int argc, char *argv[]){ if(argc != 2){ printf("error input\n");exit(-1);} printf("%d\n", sum(atoi(argv[1])));return 0;} ...
include "stdio.h"void main(){ float b ;int high;scanf("%f",&b);int a = (int)b;while(a/10) {a/=10;} high = a;printf("%d\n",high);printf("%.2f",b);return;}