exam1.c
#include<stdio.h>
void q1(){
int i;
int num1=0,num3=0;
int total=0;
for(i=399;i<=8993;i++){
num1=i%10;
num3=(i/100)%10;
if((num1+num3)==11){
total+=i;
}
}
printf("%d\n",total);
}
void q2(){
int i;
int num1=0,num3=0;
int total=0;
for(i=359;i<=8691;i++){
if(i%7==0 && i%2==0){
total+=i;
}
}
printf("%d\n",total);
}
void q3(){
int i;
int num1=0,num3=0;
int total=0;
for(i=95;i<=8505;i++){
if(i%14!=0){
total+=i;
}
}
printf("%d\n",total);
}
void q4(){
int i=0,j=0;
int total=0;
for(i=473;i<=8393;i++){
int count=0;
j=i;
while(j!=0 && count==0){
if(j%10==3||j%10==6||j%10==8)
count++;
j=j/10;
}
if(count!=0)
total+=i;
}
printf("%d\n",total);
}
void q5(){
int i;
int num1=0,num3=0;
int total=0;
for(i=486;i<=8817;i++){
num1=i%10;
num3=(i/100)%10;
if((num1*num3)==16)
total+=i;
}
printf("%d\n",total);
}
int main(){
q1();
q2();
q3();
q4();
q5();
return 0;
}
exam2.py
def q1():
total=0;
for i in range(399,8993+1):
num1=i%10;
num3=int(i/100)%10;
if((num1+num3)==11):
total+=i;
print(total)
def q2():
total=0
for i in range(359,8691+1):
if(i%7==0 and i%2==0):
total+=i
print(total)
def q3():
total=0
for i in range(95,8505+1):
if(i%14!=0):
total+=i
print(total)
def q4():
total=0
for 索引 in range(473,8393+1):
if str(索引).find("3") != -1 or str(索引).find("6") != -1 or str(索引).find("8") != -1:
total+=索引
print(total)
def q5():
total=0;
for i in range(486,8817+1):
num1=i%10;
num3=int(i/100)%10;
if((num1*num3)==16):
total+=i;
print(total)
q1()
q2()
q3()
q4()
q5()
沒有留言:
張貼留言