99问答网
所有问题
C++中,定义一个整型数组a[10]={1,2,3,4,5,6,7,8,9,10},编写一个函数实现将a数组各个数组元素的值加2。
以数组元素作函数参数
举报该问题
其他回答
第1个回答 2012-04-27
void AddTwo(int &a)
{
for (int i=0;i<10;i++) a[i] +=2;
return;
}本回答被提问者采纳
第2个回答 2012-04-27
void add_two(int *a)
{
for(int i=0;i<10;i++)
a[i]+=2;
}
第3个回答 2012-04-27
void Add2(int &a)
{
a+=2;
}
for(int i=0; i<10;i++)
Add2(a[i]);
相似回答
...给定
一个数组a[10]={1,2,3,4,5,6,7,8,9,10}
;,使用指针将数组存放的内...
答:
include<stdio.h>int main(){int
a[10]={1,2,3,4,5,6,7,8,9,10},
*p=a,*q=a+9,t; for(;p<q;p++,q--) {t=*p;*p=*q;*q=t;} for(p=a;p<a+10;p++) printf("%d ",*p); return 0;}
int
a[10]={1,2,3,4,5,6,7,8,9,10}
;
答:
D 是正确的。首先*p = &a[3]是将
数组a[10]
里的第四个数(下标从0开始,所以a[3]=4),那么p在内存中第一个指向的因该是4这个数,所以p[]={4,5,6,7,8,9,10},p[5]为数组中第六个数即9.上面的解释你应该明白了吧
编
一个
c程序:将一维
数组
中元素向右环移N位
答:
rightmove(int x[],int length );int main(void){ int
a[10]={1,2,3,4,5,6,7,8,9,
0};int count,n,len=10;// 右移位数n,len不应该这样得到,我懒得算 printf("Input n:\n");scanf("%d",&n);for(count=0;count<n%10;count++){ rightmove(a,len);} for(count=0;count<...
将a数组
中第
一个
元素移到数组末尾,其余数据依次往前平移一个位置.
c++
...
答:
第一行为
数组a
的元素个数;第二行为n个小于1000的正整数。【输出】平移后的数组元素,每个数用一个空格隔开。【输入样例】
10
1
2
3
4
5
6 7 8 9 10 【输出样例】2 3 4 5 6 7 8 9 10 1 include<bits/std
c++
.h> using namespace std;int n,i
,a[
10000];int main(){ cin>>n;f...
我有
一个
TXT文件,内容为
1,2,3
4,5,6
7,8,9
10,
11,12 如何用
c++
程序
答:
include <fstream>#include <iostream>#include <vector>using namespace std;struct tag{ int i1; int i2; int i3; friend ostream& operator<<(ostream& os, const tag& t){ return os << t.i1 << ", " << t.i2 << ", " << t.i3; }};void main(){ ...
3
.设计一个完整的
C++
程序
定义一个
类模板,利用它
实现10个
整数、浮点数...
答:
并传入相应的数据进行排序。然后,通过调用PrintSorted
函数,
打印排序后的结果。输出示例:Sorted Integers:
1
2
3
4
5
6 7 8 9 10 Sorted Floats: 1.3 2.5 3.9 4.1 5.6 6.4 7.2 8.7 9.8 10 Sorted Characters: a b c d e f g h i j ...
C++
如何获得
一个数组
中 有多少个数
答:
===
一个数组
x[]中 有多少个元素:int x
[]={1,2,3,4,5,6,7,8,9,10}
;n = sizeof(x) / sizeof(int);=== 控制台输入 2 5 6 7回车 输出结果4(输入了4个数) ,用下法:include <stdio.h> int main(){ int x[]={1,2,3,4,5,6,7,8,9,10};int i, n,c;n = si...
用
c++编写
程序
,编写一个3
*3矩阵转置的
函数,
在main()函数中输入数据
答:
2、
定义一个
名为array1的
数组
并赋值:double
[,]
array1 = new double
[3,
3] {
{ 1, 2, 3
},
{
4, 5, 6
}, {
7, 8, 9
} };。3、右键解决方案下的项目名,添加-类,创建一个名为“turnzhi”的类。4、转置类的代码为:public static double[,] 转置(double[,] A){ int ...
c++,
cout输出
一个数组
...空格问题..
答:
int
a[]={1,2,3,4,5,6,7,8}
;for(int i = 0;i<7;i++)//8-
1=
7 cout<<a[i]<<" ";cout<<a[i];vector a;...数据设置 int len= a.size();for(int i = 0;i< len-1 ;i++)// len-1 cout<<a[i]<<" ";cout<<a[i]; //这里用空格隔开 ...
大家正在搜
相关问题
c++编程问题 给定一个数组a[10]={1,2,3,4,5...
用C++编写函数,将n=4插入有序数据中,插入后数组仍然有序...
c++问题。有说明:int a[10]={1,2,3,4,5...
您好 我想请教一个C++问题 main() { int f;...
C++中如下定义是否合法,int a[3][4]={{1,2...
c++中如何将字符串类似于s="1 2 3 4 5 6 7 ...
C++,已知a数组int a[10]={1,2,3,4,5,...
已有定义int a[10]={1,2,3,4,5,6,7,8...