1732 - 字符数组的定义赋值与输出实验

按以下操作完成指定的字符数组实验

定义字符数组ch1[100]并直接赋初始值“Hello Hi” (要求用{ }赋值并加上结束符'\0')

定义字符数组ch2[50]并直接赋初始值“Nice to Meet You” (要求用""赋值)

输出字符数组ch1的字符串并换行

输出字符数组ch2的字符串并换行

在同一行连续输出字符ch1[1],ch1[3],ch1[5],ch1[7]并换行

在同一行连续输出字符ch2[0],ch2[2],ch2[4],ch2[6],ch2[8]并换行


见一本通P84-86页

题目输入

题目输出

输入/输出样例

题目输入


                

题目输出


                

C++解答

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
char ch1[101]="Hello Hi",ch2[51]="Nice to Meet You";
int main()
{
  cout<<ch1<<endl<<ch2<<endl;
  cout<<ch1[1]<<ch1[3]<<ch1[5]<<ch1[7]<<endl;
  cout<<ch2[0]<<ch2[2]<<ch2[4]<<ch2[6]<<ch2[8]<<endl;
  return 0;
}
时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题