1:1~100的偶数累加,奇数相乘
一。请用三种结构实现从1到100之间的偶数累加,奇数相乘,并将偶数累加的结果输出,奇数相乘的结果输出。
1)用for语句完成。
#include
using namespace std;
int main()
int sum=0;
double pro=1;
for(int i=2;i<=100;i=i+2)
sum=sum+i;
pro=pro*(i-1);
cout<<"1到100之间的偶数和为:" 2)用while语句完成。 #include using namespace std; int main() int sum=0; double pro=1; int i=2; while(i<=100) cout<<"偶数和为:" 3)用do-while语句完成。 #include using namespace std; int main() int sum=0; double pro=1; int i=2; dowhile(i<=100); cout<<"偶数和为:" 4)以下是我自已用for语句做的,还要修改的。 #include using namespace std; int main() int i,j,n,h; for(n=1000;n<=9999;n++) for(h=1;h<=100;h++) return 0; 2:aabb类的车牌号。 1.一辆卡车违犯交通规则,撞人后逃跑。现场有三人目击事件,但都没有记住车号,只记下车号的一些特征。 甲说:牌照的前两位数字是相同的;乙说:牌照的后两位数字是相同的,但与前两位不同;丙是位数学家,他说: 四位的车号刚好是一个整数的平方。请根据以上线索求出车号。 #include<> void main() int a,b,c,d,n; for(int i=0;i<100;i++) 3:颠倒顺序问题。 一。编写字符串反转函数 mystrrev(),该函数的功能为将指定字符串的字符顺序颠倒排列。然后,再编写主函数验证之,函数声明如下: void mystrrev(char string) 方法:(1)#include using namespace std; #include void mystrrev(char string) int x=strlen(string); int i=0; while(i int main() char string[7]="abcdef"; cout<<"原来的排序是:" cout<<"反转后的排序是:" 方法:(2)#include void mystrrev(char string) int x=strlen(string); int i=0; while(i int main() cout<<"please input " cout<<"反转后的排序是:" 4:各种符号=%的使用。 一。各种符号=,*的使用。 #include<> void main() int a=20, b=6;