Fibonacci数列
1 #include <stdio.h>
2 int fun(int x)
3 {
4 if(x==1||x==2) //注意递归的结束
5 return 1;
6 else
7 return fun(x-1)+fun(x-2);
8 }
9 int main()
10 {
11 int n,i;
12 scanf("%d",&n);
13 printf("%d",fun(n)%10007);
14 return 0;
15 }
难点:递归的使用
时间转换
1 #include<iostream>
2 using namespace std;
3 int main()
4 {
5 int t;
6 cin>>t;
7 int h,m,s;
8 h=t/3600;
9 m=t%3600/60;
10 s=t%3600%60;
11 cout<<h<<":"<<m<<":"<<s<<endl;
12 return 0;
13 }
字符串小写转大写
#include <ctype.h> http://baike.baidu.com/link?url=WH94T6MdbBKwTAqcoGmMz4neQkY7m1odU14d1TxTDm3fHEyhJeGtvJJ9GyX9ZWn3JsfYW1m8Aavez0zfETYjx_
1 for(i = 0; i < sizeof(s); i++)
2 s[i] = toupper(s[i]);
矩阵相交面积计算,方法不错
1 #include <iostream>
2 #include <algorithm> //用来使用max min
3 #include <cmath>
4 #include <cstdio>
5 using namespace std;
6 int main()
7 {
8 double x1, x2, y1, y2;
9 double q1, q2, w1, w2;
10 while (cin >> x1 >> y1 >> x2 >> y2 >> q1 >> w1 >> q2 >> w2)
11 {
12 double xx = max(min(x1, x2), min(q1, q2));
13 double yy = max(min(y1, y2), min(w1, w2));
14 double xxup = min(max(x1, x2), max(q1, q2));
15 double yyup = min(max(y1, y2), max(w1, w2));
16 if (xxup > xx)
17 printf("%.2f
", fabs((xx)-(xxup))*fabs((yy)-(yyup)));
18 else printf("0.00
"); //别忘了不想交的时候输出0
19 }
20 }