#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int fun(int n){
if(n == 1 || n == 2){
return 1;
}
else{
return fun(n-1)+fun(n-2);
}
}
int main(){
int n;
FILE *fp;
//scanf("%d",&n);
n = 20;
int sum =0;
int t;
if((fp=fopen("fab.txt","w+"))==NULL){
printf("cannot write this file\n");
exit(0);
}
for(int i = 1; i <= n; i++){
fprintf(fp,"n=%d f(%d)=%d\n",i,i,t=fun(i));
sum += t;
}
cout << sum << endl;
fclose(fp);
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int i,j;
int a,b,c,d;
int t;
for(i = 1000; i <= 9999; i++){ //车牌是个4位数
t = i;
d = t%10; // d 是个位
t /= 10;
c = t%10; // c 是十位
t /= 10;
b = t%10; // b 是百位
t /= 10;
a = t%10; // a 是千位
if(a==b && c==d){ // 前面两位数字相同,后面两位数字相同
for(j = sqrt(1000.0); j < 100; j++){ //4位的车号是一个整数的平方
if(j*j == i){
cout << i << endl;
cout << j << endl;
}
}
}
}
}
#include<stdio.h>
struct Date{
int y;
int m;
int d;
}time;
int main(){
int CheckYear(struct Date time);
int CheckMonth(struct Date time);
int CheckDay(struct Date time);
struct Date ReturnTime(struct Date time,int days);
int days;
struct Date timeLater;
while(1){
printf("请输入年月日(形如:1995 2 26)\n");
scanf("%d %d %d",&time.y,&time.m,&time.d);
if(CheckYear(time)&&CheckMonth(time)&&CheckDay(time)){
printf("输入正确\n");
break;
}else{
printf("输入有误!\n");
}
}
printf("输入天数:\n");
scanf("%d",&days);
timeLater = ReturnTime(time,days);
printf("%d %d %d",timeLater.y,timeLater.m,timeLater.d);
return 0;
}
int CheckYear(struct Date time){
if(time.y<1000||time.y>9999)
return 0;
//检查闰年
if((time.y%4==0&&time.y%100!=0)||time.y%400==0)
return 2;//闰年
else return 1;//非闰年
}
int CheckMonth(struct Date time){
if(time.m>0&&time.m<13)
return 1;
else
return 0;
}
int CheckDay(struct Date time){
if(time.m==1||time.m==3||time.m==5||time.m==7||time.m==8||time.m==10||time.m==12){//大的月份
if(time.d>0&&time.d<32)
return 1;
else return 0;
}else if(time.m==2){ // 2月份特殊
if(CheckYear(time)==2){ //闰年 29天
if(time.d>0&&time.d<30)
return 2; //闰年二月
else return 0;
}else{
if(time.d>0&&time.d<29) //非闰年2月28天
return 1;
else return 0;
}
}else{ //其余月份30天
if(time.d>0&&time.d<31)
return 1;
else return 0;
}
}
//高斯日记算法
struct Date ReturnTime(struct Date time,int days){
struct Date timeLater;
int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(int i=1;i<days;i++){ // 每次加1天
if(CheckYear(time)==2) // 闰年调整2月份天数
a[2]=29;
else
a[2]=28;
time.d=time.d%a[time.m]+1;
if(time.d==1){ //判断本月最后一天
time.m=time.m%12+1;
if(time.m==1) //判断本年最后一月
time.y++;
}
}
timeLater=time;
return timeLater;
}