随笔分类 -  跟我一起学C++

摘要:终于写了一些有用的代码,第一个是执行在999内挑选出水仙花数,并存入文件里,第二个是读取文件,显示内容。void out_file(){ int k=100,l,m,n,count=0; ofstream ofile; ofile.open("myfile.txt"); ofile<<"水仙花数有:"<<endl; do{ l=k/100; n=k%10; m=(k-l*100-n)/10; if(k==l*l*l+m*m*m+n*n*n){ ofile<<l<<"的3次方+"<& 阅读全文
posted @ 2009-09-14 10:09 j2ee技术 阅读(205) 评论(0) 推荐(0)
摘要:s=a+aa+aaa+...+aa...a(n个a),其中a是1-9中的一个数字。 这个没有难度。#include "iostream"#include "cmath"using namespace std;void main(){ int n,k; cout<<"请输入数字(1-9):"<<endl; cin>>k; if(k<1||k>9){ cout<<"输入错误!"<<endl; return; } cout<<" 阅读全文
posted @ 2009-09-11 15:07 j2ee技术 阅读(2274) 评论(0) 推荐(0)
摘要:#include "iostream"#include "cmath"using namespace std;void main(){ int n,i; double result=0; cout<<"请输入正整数:"<<endl; cin>>n; if(n<1){ cout<<"输入错误!"<<endl; return; } result=1; for(i=2;i<=n;i++) result*=i; cout<<result&l 阅读全文
posted @ 2009-09-07 16:58 j2ee技术 阅读(172) 评论(0) 推荐(0)
摘要:突然发现自己连一元二次方程怎么算的都不知道了。想了半天,拿起笔来才顺手些了给x2+2x+1=0.悔恨啊。#include "iostream"#include "cmath"using namespace std;int main(){ double a,b,c; double delta,x1,x2; int sign,stop; cout<<"输入3个系数a(a!=0),b,c"<<endl; cin>>a>>b>>c; if(a==0){ cout<<&qu 阅读全文
posted @ 2009-09-07 13:58 j2ee技术 阅读(1451) 评论(0) 推荐(0)
摘要:1.判断它是否能被2整除。 #include "iostream"using namespace std;int main(){ int input; cout<<"Which number do you want to test?/n"; cin>>input; if(input&1) cout<<"number "<<input<<" is odd."; else cout<<"number "<<i 阅读全文
posted @ 2009-09-07 11:10 j2ee技术 阅读(732) 评论(0) 推荐(0)
摘要:#include "iostream"using namespace std;int main(){ int a,b,c; int max,min; cout<<"请输入三个不等整数:/n"; cin>>a>>b>>c; if(a>b){ max=a;min=b; } else;{ max=b;min=a; } if(c>max) cout<<c<<"/t"<<max<<"/t"<<min< 阅读全文
posted @ 2009-09-07 10:41 j2ee技术 阅读(207) 评论(0) 推荐(0)
摘要:因为微软出的VS2008什么的安装包太大了,以前安过一次而且很不成功很不爽造就了一大堆垃圾文件。我就下了一个天朝的简化版。加上编译器一共才160M。好吧。我不广告了但的确。没必要为个C++装那么脓肿的玩意。写了按照教程写了一个简单的测试程序,在编译的时候报错“Cannot open include file: 'iostream.h': No such file or directory”。旧的源文件如下:#include <iostream.h>char name[16];void main(){cout<<"enter your name: 阅读全文
posted @ 2009-08-27 13:32 j2ee技术 阅读(3118) 评论(0) 推荐(0)