我被要求对这些问题做一个程序段。
While(a<20){
a++
cout<< A[a][50]<<"\n";
}
编辑1:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,n,m;
int A [20][50]={};
a=1;
cout<<"enter your number:"<<endl;
cin>>n;
cin>>m;
cout <<A [n][m] <<"\n";
while (a> 20){
cout << A [a][49]<<"\n";
}
system ("pause");
return 0;
编辑2:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a,n,m;
int A [20][50]={};
a=1;
cout<<"enter your number:"<<endl;
cin>>n;
cin>>m;
cout <<A [n][m] <<"\n";
while (a < 20){
cout << A [a][49]<<"\n";
}
a++;
}
system ("pause");
return 0;
}
float num; float d[num];
cout<<"How many number do you want to enter to find there squure?"<<endl;
cin>>num;
for(int i; i<num; i++){
cin>>d[i];}
for(int i; i<num; i++) {
result[i]=d[i]*d[i];}
for(int i=0; i<num i++){
cout<<result[i];
编辑1
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main()
{
int b;
int x;
int A[]={};
int N;
int n;
cout <<"enter value for N:"<<endl;
cin>>N;
x=1;
n=N;
while (x<=N){
b =x*x;
A[n]=b;
x++ ;
}
cout <<A[n]<<"\t";
system ("pause");
return 0;
}
编辑2
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x=1,b;
int N=5;
while (x<=N){
b=x*x;
cout<<b<<"\n";
x++;
}
system("pause");
return 0;
}
我不知道该怎么做:(
这些代码正确吗?除了3号,因为我真的不知道该怎么做。任何人都可以纠正这些吗?非常感谢你 :)
编辑:我对数字1做出了新的回答,并使其可编译:)编辑:我现在对数字2进行了编辑。但是似乎无法将其打印到数组中。编辑:能够使#2工作,但我确定这是否是被询问的输出:s
这是我对第一个问题的理解。
#include <iostream>
using namespace std;
int main(void) {
// Decalare an array of 20 rows,
// each containing an array of 50 integers.
int A[20][50];
// Initialize all the elements of the array to 0.
// Invariant: we have initialized `row` rows.
for (int row = 0; row != 20; ++row) {
// Invariant: we have initialized `col` columns.
for (int col = 0; col != 50; ++col)
A[row][col] = 0;
}
// We can now fill in the values we want into the array.
// For this example, we are filling the 1st row with 0,
// 2nd row with 1, 3rd row with 2 and so on.
// You can fill it with any values you like.
for (int row = 0; row != 20; ++row) {
for (int col = 0; col != 50; ++col)
A[row][col] = row+1;
}
// Display the last element of each row.
// Invariant: we have printed `row` rows.
for (int row = 0; row != 20; ++row) {
// The index -1 gives us the last element in an array.
cout << "A[" << row << "][50]: " << A[row][-1] << endl;
}
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句