N
直到 0N is a multiple of 11.
N is not a multiple of 11.
n
(因为整数存不下) 直到 0
char n[1000] = {0};
while(scanf("%s", n)){
if(*n == '0' && strlen(n) == 1){
break;
}
else{
...
}
}
for
回圈及回圈变数 i
控制一加一减每个位数,要记得是字元所以要 - '0'
int i;
int difference = 0;
for(i = 0; i < strlen(n); i++){
if(i % 2 == 0){
difference = difference + (n[i] - '0');
}
else{
difference = difference - (n[i] - '0');
}
}
if(difference % 11 == 0){
flag = true;
}
if(flag){
printf("%s is a multiple of 11.\n", n);
}
else{
printf("%s is not a multiple of 11.\n", n);
}
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
int main(){
char n[1000] = {0};
while(scanf("%s", n)){
if(*n == '0' && strlen(n) == 1){
break;
}
else{
int i;
bool flag = false;
int difference = 0;
for(i = 0; i < strlen(n); i++){
if(i % 2 == 0){
difference = difference + (n[i] - '0');
}
else{
difference = difference - (n[i] - '0');
}
}
if(difference % 11 == 0){
flag = true;
}
if(flag){
printf("%s is a multiple of 11.\n", n);
}
else{
printf("%s is not a multiple of 11.\n", n);
}
}
}
return 0;
}
鲜红创伤 在夜里 暗淡无光 愈合後 变成透明的疤 日光下 仍是无光 三日月的慌 莫过於再十...
这是我30天的自我挑战,每篇文章都记录着自己的成长与收获,也请大家多多指教! Android是甚麽...
昨天後来在看效果时,有发现过渡动画的元素已经完全超出卡片组件的范围了,这个不是我们想要的效果 理想...
上一篇介绍过了I2C的基本原理以及相关的函数,这一篇会介绍EEPROM来做为I2C实作的示范。 什麽...
今天,我们要来作Alpine Linux的initramfs bootstrapping。 在近代的...