#include
int main(){
double x,i,sum=0,n=0,x3=1,x2=1,x1=1,a=0;
scanf("%lf",&x);
for(i=1;i<=x;i++){
//元素是斐波那契数列
a=0;
x3=x2+x1;
n=x3/x2;
a=x2;
x2=x3;
x1=a;
sum=sum+n;
}
printf("sum=%.4lf",sum);
return 0;
}
-------------------
#include
int main(){
int x,i,j=0,a,k,sum;
scanf("%d",&x);
for(i=1;i<=x;i++){//循环来反复给予钱
//判断当天要给多少,用j表示
k=i;
j=0;
for(a=1;k>0;a++){
k=k-a;
j++;
}
sum=sum+j;
}
printf("%d",sum);
return 0;
}
--------------------
#include
#include
int main()
{
char c;
c=getchar();
while(c!='n')
{
if(c=='-')printf("fu");
else if(c=='0')printf("ling");
else if(c=='1')printf("yi");
else if(c=='2')printf("er");
else if(c=='3')printf("san");
else if(c=='4')printf("si");
else if(c=='5')printf("wu");
else if(c=='6')printf("liu");
else if(c=='7')printf("qi");
else if(c=='8')printf("ba");
else if(c=='9')printf("jiu");
c=getchar();
if(c!='n')printf(" "); //每循环一次 打印一个空格
}
return 0;
}
--------------------------------------
#include
int main()
{
int n, sum=0, i, t, j, a, f, c=0;
scanf("%d",&n);
for(i=0;i
scanf("%d",&a);
t=a;
sum=0;
while(t)
{
sum+=t%10;
t/=10;
}
f=sum;
c=0;
for(j=2;j<=9;j++)
{
t=a*j;
sum=0;
while(t)
{
sum+=t%10;
t/=10;
}
if(sum==f)
{
c++;
}
}
if(c==8)
{
printf("%dn",f);
}
else
{
printf("NOn");
}
}
return 0;
}
----------------------------------
//输入总额,输出多少个五分,三分,一分,一共多少个硬币,即前面三个数据的和
//总方案个数就是行数
//简单来讲就是x=5*a+3*b+c
//循环中erfen和yifen可以在每次wufen循环中重新获得最大值,前提是zone不变
#include
int main(){
int wufen,erfen,yifen,hangshu=0,zone;
scanf("%d",&zone);
for(wufen=zone/5;wufen>0;wufen--){
for(erfen=zone/2;erfen>0;erfen--){
for(yifen=zone;yifen>0;yifen--){
if(wufen*5+erfen*2+yifen==zone){
printf("fen5:%d, fen2:%d, fen1:%d, total:%dn",wufen,erfen,yifen,wufen+erfen+yifen);
hangshu++;
}
}
}
}
printf("count = %d",hangshu);
return 0;
}
----------------------------
#include
int main(){
int x,a,b,c,d,e,f,i;
scanf("%d",&x);
for(i=1;i<=x;i++){
scanf("%1d%1d%1d%1d%1d%1d",&a,&b,&c,&d,&e,&f);
if((a+b+c)==(d+e+f)){
printf("You are lucky!n");
}else{
printf("Wish you good luck.n");
}
}
return 0;
}
------------------------------
#include
int main()
{
int A,b,c,d;
int a[4];
scanf("%d",&A);
for(b=0;b<=3;b++)
{
a[b]=A;
A++;
}
printf("%d%d%d ",a[0],a[1],a[2]);
printf("%d%d%d ",a[0],a[1],a[3]);
printf("%d%d%d ",a[0],a[2],a[1]);
printf("%d%d%d ",a[0],a[2],a[3]);
printf("%d%d%d ",a[0],a[3],a[1]);
printf("%d%d%dn",a[0],a[3],a[2]);
printf("%d%d%d ",a[1],a[0],a[2]);
printf("%d%d%d ",a[1],a[0],a[3]);
printf("%d%d%d ",a[1],a[2],a[0]);
printf("%d%d%d ",a[1],a[2],a[3]);
printf("%d%d%d ",a[1],a[3],a[0]);
printf("%d%d%dn",a[1],a[3],a[2]);
printf("%d%d%d ",a[2],a[0],a[1]);
printf("%d%d%d ",a[2],a[0],a[3]);
printf("%d%d%d ",a[2],a[1],a[0]);
printf("%d%d%d ",a[2],a[1],a[3]);
printf("%d%d%d ",a[2],a[3],a[0]);
printf("%d%d%dn",a[2],a[3],a[1]);
printf("%d%d%d ",a[3],a[0],a[1]);
printf("%d%d%d ",a[3],a[0],a[2]);
printf("%d%d%d ",a[3],a[1],a[0]);
printf("%d%d%d ",a[3],a[1],a[2]);
printf("%d%d%d ",a[3],a[2],a[0]);
printf("%d%d%d",a[3],a[2],a[1]);
return 0;}
-------------------------
#include
#include
int main(){
int x,j=0;
char a[10];
scanf("%d",&x);
while(scanf("%s",a)){
if(strcmp(a,"End")==0)break;
if(j!=x){
j++;
if(strcmp(a,"ChuiZi")==0)puts("Bu");
else if(strcmp(a,"JianDao")==0)puts("ChuiZi");
else if(strcmp(a,"Bu")==0)puts("JianDao");
}else{
j=0;
puts(a);
}
}
return 0;
}
----------------------------------
#include
int main(){
int n,u,d,t=0;
scanf("%d %d %d",&n,&u,&d);
while(n>0){
t++;
n=n-u;
if(n<=0)break;
n=n+d;
t++;
}
printf("%d",t);
return 0;
}
----------------------
#include
int jiecheng(int n){
int ret=1;
for(int i=1;i<=n;i++){
ret*=i;
}
return ret;
}
int main(){
double a,b,c;
int count=1;
double sum=1;
scanf("%lf",&a);
for(int i=1;;i++){
b=jiecheng(i);
c=1.0/b;
count++;
sum+=c;
if(c<=a)
break;
}
printf("e=%.3lf,count=%d",sum,count);
return 0;
}
----------------
#include
int main(){
int tag,x;
scanf("%d %d",&tag,&x);
int i,n;
for(i=1;i<=x+1;i++){
scanf("%d",&n);
if(n<0){
printf("Game Overn");
break;
}
if(i==x+1){
printf("Game Overn");
break;
}
if(n==tag){
if(i==1){
printf("Bingo!n");
return 0;
}else if(i==2||i==3){
printf("Lucky You!n");
return 0;
}else{
printf("Good Guess!n");
return 0;
}
}else if(n>tag){
printf("Too bign");
}else if(n
}
}
return 0;
}
-------------------------
#include
int main(){
int tou,jiao;
int tuzi,ji,f=1;
scanf("%d %d",&tou,&jiao);
for(tuzi=0;tuzi<=tou;tuzi++){
ji=tou-tuzi;
if(2*ji+4*tuzi==jiao){
f=0;
printf("chickens = %d; rabbits = %d",ji,tuzi);
}
}
if(f!=0){
printf("No solution!");
}
return 0;
}
-----------------
#include
int main(){
int max,min,x,i;
int a,b,c,d,t;
int flag=0;
scanf("%d",&x);
for(i=1;i<=7;i++){
a=x/1000;
d=x%10;
c=(x/10)%10;
b=(x/100)%10;
if(a>b){t=a,a=b,b=t;}
if(a>c){t=c,c=a,a=t;}
if(a>d){t=a,a=d,d=t;}
if(b>c){t=b,b=c,c=t;}
if(b>d){t=b,b=d,d=t;}
if(c>d){t=c,c=d,d=t;}
max=d*1000+c*100+b*10+a;
min=a*1000+b*100+c*10+d;
x=max-min;
if(flag!=0){
printf("n");
}
printf("%04d-%04d=%04d",max,min,x);
flag++;
if(x==6174){
break;
}
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)