摘要:
在C语言中,多个表达式可以用逗号分开,其中用逗号分开的表达式的值分别结算,但整个表达式的值是最后一个表达式的值。 假设b=2,c=7,d=5, a1=(++b,c--,d+3); a2=++b,c--,d+3;在C语言中,多个表达式可以用逗号分开,其中用逗号分开的表达式的值分别结算,但整个表达式的值是最后一个表达式的值。 假设b=2,c=7,d=5, a1=(++b,c--,d... 阅读全文
摘要:
struct Test { Test( int ) {} Test() {} void fun() {} }; void main( void ) { Test a(1); a.fun(); Test b(); b.fun(); } 解答:b.fun(); //b不是Test的实例对象类是结构体的扩展,在类中封装了对数据成员的操作,缺省的成员为私有的,而结构体为公有的,这就... 阅读全文
摘要:
#include <iostream>using namespace std;void UpperCase( char str[] ) // 将 str 中的小写字母转换成大写字母{ for( int i=0; i<sizeof(str)/sizeof(str[0]); ++i ) if( 'a'<=str[i] && str[i]<='z' ) st... 阅读全文
摘要:
以前的博客是csdn的 http://blog.csdn.net/xtayaitak 阅读全文
摘要:
/* 789 - seven hundred and eighty nine */ /*思路:这人题思路很简单但是用c++程序实现起来比较繁琐,看了答案才知道 可以把 switch(){case}可以改成数组。哎。效率就是不行呀~! 如 char *a[]={"","one","two".........}*/ #include #include using namespace std;... 阅读全文
摘要:
/*输入一个自然数,将该自然数的每一位数字反序输出,例如:输入 12345,输出54321*/ #include using namespace std; /* int main() { cout>ch; cout=0;i--) { cout>num; do { digit=num%10; num=num/10; cout0); return 0; ... 阅读全文
摘要:
难点:怎么把行标i 和每行显示的数据的个数联系起来,怎么找出i和j的关系? */ #include using namespace std; int main() { int i,j; for(i=1;i0;j--) cout=1;i--) { for(j=(4-i)*2;j>0;j--) cout<<" "; for(j=1;j<=2*i-1;j++) ... 阅读全文
摘要:
/*直角三角形三条边满足勾股定律。编写程序,找出三角边长度小于50的所有三角形。*/ /*思路:设三边为a b c 玫举所有小于50的三角形。先测试能不能三角形。然后再测试勾股定律。*/ /*注意:直角三角形三边长3 4 5和4 3 5是同一个三角形。*/ #include using namespace std; int main() { int a,b,c,i=0; int cou... 阅读全文
摘要:
/*判断是否为回文数 例如:18981 思路:数字当成字符串数组,数组的下标访问每个元素判断是否为回文数。*/ #include using namespace std; int main() { char ch[30]; cout>ch; cout=len-1) cout<<"是回文数"<<endl; else cout<<"不是回文数"<<endl; /*if... 阅读全文
摘要:
/* 1 空格4次 数字1次 2 2 空格3次 数字2次 3 3 3 空格2次 数字3次 4 4 4 4 5 5 5 5 5 */ #include using namespace std; int const N=5; int main() { for(int i=1;i<=N;i++) { for(int j=1;j<=N-i... 阅读全文
摘要:
/*输出以下图案 * cout using namespace std; int main() { for(int i=1;i0;i--) { for(int j=1;j<=7-i;j++) cout<<" "; for(j=1;j<=i;j++) cout<<"* "; cout<<endl; } } 阅读全文
摘要:
/*找出10000以内的同构数 同构数 376*376=141376 思路:1、输入一个数num 先判断是几位数。记住数位length。 2、然后算它(num)的平方, square。 3、取square的后length位的数值temp 4、temp与num相等,则是同构数。 */ #include #include using namespace std; int... 阅读全文
摘要:
http://topic.csdn.net/u/20101002/08/1106d03a-dfef-499d-aad9-5d85af21fecb.html?72693 阅读全文
摘要:
/*“水仙花数”是指一个三位数,其各位数的立方和等于该。 例如:153=1的立方+5的立方+3的立方 编写程序:输出所有“水仙花数“ 思路:1、取一个三位数,取百位,十位,个位。 2、分别算出他们的立方和。 4、比较 */ #include #include using namespace std; int main() { int num; int bw,sw,gw... 阅读全文
摘要:
/*针对职工工资的发放,给出各种标额最少的张数的付款方案, 票额包括:100元、50元、20元、10元、5元、2元、和1元。 思路:1、设工资数为total 2、100元的张数为total/100 50元的张数为total%100/50 20元的张数为total%100%50/20 10元的张数为total%100%50%20/10 5元 ... 阅读全文
摘要:
/*编写程序,用随机数函数产生1000个1-6之间的随机数。用这1000个随机数分别代表骰子6个面的面值, 要求:输出6个面的面值各自出现的次数。 思路: */ #include #include using namespace std; int main() { int num; int a[6]={0,0,0,0,0,0}; for(int i=0;i<=1000;i++) {... 阅读全文
摘要:
/*例如:有两个线性表LA=(1,5,7,15) LB=(3,6,8,9,13,15,17) 则: LC=(1,3,6,8,9,13,15,15,17) 上述问题要求可知,LC中的数据元素或是LA中的数据元素,或是LB中的数据元素,则首先设LC为空表,然后将LA或LBs中的元素逐个插入到LC当中。 为使LC中元素按值非递减排列... 阅读全文
摘要:
此刻,我想好多人已经放弃了,但是我不会的,看见了一句话,挺好。真的,立刻就把这句话放到了我的博客的标题下面。有些人说,我一直在幻想中生活,在幻想中学习。其实我没有,我也不会,我的经历告诉我,坚持就是胜利。我想我会克服一切困难,达到我的目标 阅读全文
摘要:
/*编写一个递归函数完成以下公式的运算*/ //sum(n)=1-1/2+1/3-1/4......(其中n>0) #include using namespace std; //非递归算法 float FUN(int n) { int m=1,temp=1; float total=0.0; while(m!=n+1) { total=total+1.0/m*temp; //注... 阅读全文
摘要:
/*不交换中间变量交换两个数*/ #include using namespace std; void Fun(int&x,int&y) { x=x+y; y=x-y; x=x-y; } int main() { int a=3,b=4; cout<<"交换前"<<endl<<"a="<<a<<"\t"<<"b="<<b<<endl; Fun(a,b); cout<<"交换后&quo 阅读全文