c语言编程输入一个整数,判断该整数是否全部由奇数字组成或全部由偶数字组成? 用C语言编程:输入一个整数,判断这个数是奇数还是偶数。
\u8f93\u5165\u4e00\u4e2a\u6574\u6570,\u5224\u65ad\u8be5\u6574\u6570\u662f\u5426\u5168\u90e8\u7531\u5947\u6570\u5b57\u7ec4\u6210\u6216\u5168\u90e8\u7531\u5076\u6570\u5b57\u7ec4\u6210\uff1f\u7b97\u6cd5\u5440\uff01\u6709\u4e00\u4e2a\u975e\u5e38\u4f5c\u5f0a\u7684\u65b9\u6cd5\uff0c\u9996\u5148\u8f93\u5165\u5230string\u7c7b\u578b\u7684\u53d8\u91cf\u91cc\uff0c\u6bcf\u4e00\u4e2a\u4f4d\u7f6e\u5206\u79bb(s1[i]-'0')\uff0c\u5f97\u51fa\u7b2ci\u4f4d\u6570\u5b57\u7684\u65b9\u5f0f\uff0c\u904d\u5386\u5224\u65ad\u662f\u5426\u6bcf\u4e00\u4f4d\u662f\u5947\u6570\u6d3b\u662f\u5076\u6570\uff0c\u4ece0\u904d\u5386\u5230s1\u7684\u957f\u5ea6-1\uff0c\u957f\u5ea6\u51fd\u6570\u53c2\u8003\u767e\u5ea6\uff0c\u597d\u50cf\u662f(s1.length())\u3002\u5bf9\uff0c\u8fd9\u6837\u5f88\u4f5c\u5f0a\uff01
\u4e0d\u8fc7\u524d\u63d0\u4f60\u7528\u7684\u662fc++\uff0c\u4e0d\u662f\u7684\u8bdd\u5c31\u53d8\u901a\u4e00\u4e0b\u5427\uff5e
#include "stdio.h"
main()
{
int x;
printf("\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570");
scanf("%d",&x);
if(x%2 == 0) printf("%d\u662f\u5076\u6570\n",x);
else printf("%d\u662f\u5947\u6570\n",x);
}
C\u8bed\u8a00\uff1a
\u662f\u4e00\u95e8\u901a\u7528\u8ba1\u7b97\u673a\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e94\u7528\u5e7f\u6cdb\u3002C\u8bed\u8a00\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u63d0\u4f9b\u4e00\u79cd\u80fd\u4ee5\u7b80\u6613\u7684\u65b9\u5f0f\u7f16\u8bd1\u3001\u5904\u7406\u4f4e\u7ea7\u5b58\u50a8\u5668\u3001\u4ea7\u751f\u5c11\u91cf\u7684\u673a\u5668\u7801\u4ee5\u53ca\u4e0d\u9700\u8981\u4efb\u4f55\u8fd0\u884c\u73af\u5883\u652f\u6301\u4fbf\u80fd\u8fd0\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\u3002
\u76ee\u524d\uff0cC\u8bed\u8a00\u7f16\u8bd1\u5668\u666e\u904d\u5b58\u5728\u4e8e\u5404\u79cd\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u4f8b\u5982UNIX\u3001MS-DOS\u3001Microsoft Windows\u53caLinux\u7b49\u3002C\u8bed\u8a00\u7684\u8bbe\u8ba1\u5f71\u54cd\u4e86\u8bb8\u591a\u540e\u6765\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u4f8b\u5982C++\u3001Objective-C\u3001Java\u3001C#\u7b49\u3002
在C语言程序中先读入这个整数,然后设置二个变量,分别统计是每一位数的奇数个和偶数个数。当全部判断结束以后,只要判断如果是奇数的个数为零,或者偶数的个数为零,那么这个数就是全部由偶数或者全部由奇数组成的。
#include<stdio.h>
int main()
{ int x,n1,n2;
scanf("%d",&x);
for(n1=n2=0;x;x/=10)
if(x%2==1)n1++;
else n2++;
if(n2==0)printf("全部由奇数字组成
");
else if(n1==0)printf("全部由偶数字组成
");
else printf("由奇数字和偶数字组成
");
return 0;
}
新语言编程输入一个整数,判断该整数是否全部由基于数字组成或全部有素质。
绛旓細include <stdio.h>#include <stdbool.h>bool check(int);int main(void){int num;while (scanf("%d", &num) == 0 || num < 0){printf("杈撳叆閿欒锛岃杈撳叆姝鏁存暟\n");rewind(stdin);}if (check(num))printf("%d鏄礌鏁癨n", num);elseprintf("%d涓嶆槸绱犳暟\n", num);return 0;}...
绛旓細include "stdio.h"main(){ int x;printf("璇杈撳叆涓涓暣鏁");scanf("%d",&x);if(x%2 == 0) printf("%d鏄伓鏁癨n",x);else printf("%d鏄鏁癨n",x);} C璇█锛氭槸涓闂ㄩ氱敤璁$畻鏈缂栫▼璇█锛搴旂敤骞挎硾銆侰璇█鐨勮璁$洰鏍囨槸鎻愪緵涓绉嶈兘浠ョ畝鏄撶殑鏂瑰紡缂栬瘧銆佸鐞嗕綆绾у瓨鍌ㄥ櫒銆佷骇鐢熷皯閲忕殑鏈哄櫒鐮佷互鍙...
绛旓細include<stdio.h> int main(){int a,b;scanf("%d",&a);if (a<10) b=10;else if(a%10>=5) b=a/10*10+10;else if(a%10<5) b=a-(a%10);printf("%d",b);return 0;}
绛旓細//December 17,2014 By 12052010#include<stdio.h> #include<math.h> bool isPrime(int num){for(int i=2;i<=sqrt(num);i++)if(num%i==0) return false;return true;}int main(){int num;printf("\nInput your num: ");scanf("%d",&num);if(isPrime(num))printf("\nIt is "...
绛旓細include<stdio.h> include<math.h> int shu(long unsigned num)//鍒ゆ柇涓涓缁欏畾鐨勬暟num鏄笉鏄礌鏁 //鏄繑鍥1,鍚﹀垯杩斿洖0 { int t,i;t=sqrt(num)+1;for(i=2;i<t;i++){ if(num%i==0)break;} if(i==t)return 1;return 0;} int main(){ int n;printf("璇杈撳叆浠绘剰涓涓鏁存暟:...
绛旓細include <stdio.h> int main(){ int i ;scanf("%d", &i);if (i % 2 == 0){ printf(" 鏄鏁");} else { printf("鏄伓鏁");} return 114514;}
绛旓細include "stdio.h"include <string.h> void main(){ int i,len,sum=0;char str[10];printf("杈撳叆姝鏁存暟: ");scanf("%s",str);len=strlen(str);for(i=0;i<len;i++)sum+=str[i]-'0';printf("%s鏄%d浣嶆暟,鍚勪綅鏁板瓧涔嬪拰鏄%d\n",str,len,sum);...
绛旓細include "stdio.h"int main(int argc,char *argv[]){int n;for(n=0;n<100;n++)if(n*n%(n<10 ? 10 : 100)==n)//鍒ゆ柇:n*n鐨勫0~9闄や互10,10~99闄や互100,鐒跺悗涓巒姣旇緝鏄惁鐩哥瓑printf("%d ",n);printf("\n");return 0;}杩愯缁撴灉锛...
绛旓細include<stdio.h>//澶存枃浠 int main()//涓诲嚱鏁 { int number,i;//瀹氫箟鍙橀噺 printf("璇烽殢鏈杈撳叆涓涓鏁帮細");//鎻愮ず璇彞 scanf("%d",&number);//閿洏杈撳叆闇瑕鍒ゆ柇鐨勬暟 for(i=2;i<=number-1;i++)//寰幆浠2寮濮嬶紝鍒拌繖涓暟鐨勬帎鍓嶄竴涓暟涓烘 { if(number%i==0)//濡傛灉鍙栦綑缁撴灉涓0 bre...
绛旓細include <stdio.h>void Test(){ int temp,i; scanf("%d",&temp); if(temp<=0) { printf("杈撳叆閿欒锛岃杈撳叆姝鏁存暟") return; } for(i=2;i<temp;i++) { if(temp%i==0) { printf("%s涓嶆槸绱犳暟",temp); return; } } printf("%s...