C++语言设计作业

来源:百度知道 编辑:UC知道 时间:2024/06/11 16:37:46
1.完成一个程序,输入AbC,输出aBc.

2.完成一个程序,用三种循环方式实现1-100的总和。

3.说说指针与数组的区别。

哪位大大能帮忙写出来,谢谢了!悬赏20分。

1.
#include <iostream.h>

void main()
{
char* src = new char[100];
char* des = src;
char temp;

cout<<"Please enter the string:"<<endl;
cin>>src;
cout<<src<<endl;
while(*src!='\0')
{
temp = *src;
if(temp>='A' && temp<='Z')
{
*src += 32;
}
else if(temp>='a' && temp<='z')
{
*src -= 32;
}
src++;
}
cout<<"The string: "<<des<<endl;
}
2.
for循环:

for(int i = 1, sum = 0; i<=100; i++)
{
sum+=i;
}
while循环:
int i = 1;
int sum = 0;
while(i<=100)
{
sum+=i;
i++;
}
do while循环:
int i = 1;
int sum = 0;
do{
sum+=i;
i++;
}while(i<=100);
3.
数组要么在静态存储区被创建(如全局数组),要么在栈上被创建。数组