C&C++
共 14 篇文章
经典c程序100例==91--100
【程序91】 题目:时间函数举例1 1.程序分析: 2.程序源代码: #include "stdio.h" #include "time.h" void main() { time_t lt; /*define a longint time varible*/ lt=time(NULL);/*system time and date*/ printf(ctime(<)); /*english format output*/ printf(asctime(localtime(<)));/*tranfer to tm*/ printf(asctime(gmtime(<))); /*tranfer…
2012-11-01 09:34 · C&C++
经典c程序100例==81--90
【程序81】 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。 1.程序分析: 2.程序源代码: output(long b,long i) { printf("\n%ld/%ld=809*%ld+%ld",b,i,i,b%i); } main() {long int a,b,i; a=809; for(i=10;i<100;i++) {b=i*a+1; if(b>=1000&&b<=10000&&8*i<100&&9*i>=100) output(b,i); } } =====…
2012-11-01 09:34 · C&C++
经典c程序100例==71--80
【程序71】 题目:编写input()和output()函数输入,输出5个学生的数据记录。 1.程序分析: 2.程序源代码: #define N 5 struct student { char num[6]; char name[8]; int score[4]; } stu[N]; input(stu) struct student stu[]; { int i,j; for(i=0;i<N;i++) { printf("\n please input %d of %d\n",i+1,N); printf("num: "); scanf("%s",stu[i].num); printf("…
2012-11-01 09:34 · C&C++
经典c程序100例==61--70
【程序61】 题目:打印出杨辉三角形(要求打印出10行如下图) 1.程序分析: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 2.程序源代码: main() {int i,j; int a[10][10]; printf("\n"); for(i=0;i<10;i++) {a[i][0]=1; a[i][i]=1;} for(i=2;i<10;i++) for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]; for(i=0;i<10;i++) {for(j=0;j<=i;j++) printf("%5d",a[…
2012-11-01 09:33 · C&C++
经典c程序100例==51--60
【程序51】 题目:学习使用按位与 & 。 1.程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1 2.程序源代码: #include "stdio.h" main() { int a,b; a=077; b=a&3; printf("\40: The a & b(decimal) is %d \n",b); b&=7; printf("\40: The a & b(decimal) is %d \n",b); } ============================================================== 【程序52】 题目:学习使用按位或 | …
2012-11-01 09:33 · C&C++
经典c程序100例==41--50
【程序41】 题目:学习static定义静态变量的用法 1.程序分析: 2.程序源代码: #include "stdio.h" varfunc() { int var=0; static int static_var=0; printf("\40:var equal %d \n",var); printf("\40:static var equal %d \n",static_var); printf("\n"); var++; static_var++; } void main() {int i; for(i=0;i<3;i++) varfunc(); } ================…
2012-10-31 17:47 · C&C++
经典c程序100例==31--40
【程序31】 题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母。 1.程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。 2.程序源代码: #include <stdio.h> void main() { char letter; printf("please input the first letter of someday\n"); while ((letter=getch())!='Y')/*当所按字母为Y时才结束*/ { switch (letter) {case 'S':printf("please…
2012-10-31 17:46 · C&C++
经典c程序100例==21--30
【程序21】 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下 的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。 1.程序分析:采取逆向思维的方法,从后往前推断。 2.程序源代码: main() { int day,x1,x2; day=9; x2=1; while(day>0) {x1=(x2+1)*2;/*第一天的桃子数是第2天桃子数加1后的2倍*/ x2=x1; day--; } printf("the total is %d\n",x1); } …
2012-10-31 17:44 · C&C++
经典c程序100例==11--20
【程序11】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月 后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... 2.程序源代码: main() { long f1,f2; int i; f1=f2=1; for(i=1;i<=20;i++) { printf("%12ld %12ld",f1,f2); if(i%2==0) printf("\n");/*控制输出,每行四个*/ f1=f1+f2; /*前两个月加起来赋值给第三个月*/ f2=f1+f2; /*前两个…
2012-10-31 17:43 · C&C++
经典c程序100例 1-10
==1--10 【程序1】 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。 2.程序源代码: main() { int i,j,k; printf("\n"); for(i=1;i<5;i++) /*以下为三重循环*/ for(j=1;j<5;j++) for (k=1;k<5;k++) { if (i!=k&&i!=j&&j!=k) /*确保i、j、k三位互不相同*/ printf("%d,%d,%d\n",i,j,k); } } =========…
2012-10-31 17:42 · C&C++
gcc 执行c++报错
D:\cpp>g++ hello.cc Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import) c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line. This should work unless it involves…
2012-07-09 10:26 · C&C++
VC6最基本
高级语言C++程序设计【chap4】【p119-1】【我的自考书-刘璟周玉龙书】 1.VC6使用: <1>.编译:"Build"-->"Compile"=======> Ctrl+F7; <2>.连接:"Build"-->"Build" =======> F7; <3>.运行:"Build"-->"Execute"=======> Ctrl+F5; 2.【page119页 练习题1:】 /* 1.输入3个实数,打印最大最小值到终端 */ #include <iostream> using namespace std; int main(){ double d1,d2,d3; cout<<"输…
C的函数声明和形参
<1>函数声明 最近看C语言,很迷惑,有些地方有函数声明有些地方没有。 查了下教材,做下小结,笔抄写一遍,网上记一遍,备忘! 有以下三种情况不用函数声明,可以直接调用: 1.被调函数返回类型为整形或者char型,系统会自理。 举例: //代码1 #include <stdio.h> int main(){ int a=30; double d=4.4334; printf("a=%d",call(a)); return 0; } int call(int d){ printf("HelloWorld\n"); return d; } 正确。如果将call函数的返回类型改为double呢? /…
2012-04-25 11:15 · C&C++
C语言的32个关键字
刚才在javaeye搜索了下C的关键字,竟然没有人备注。 大家好记性,我java还行,C不行,备个注: break case continue default do else for goto if return switch while static // void char double float int long short enum signed unsigned // auto const extern register sizeof typedef struct union volatile
2012-04-24 16:34 · C&C++