0
Struct un c++
Hi people, y habe a cuestiĂłn, how yo copy struct a in struct b ? Ej struct a={1,0,1} ; struct b {0,0,0} after copy ( b=a ) b {1,0,1}
3 Answers
0
#include <stdio.h>
struct Number{
int x,y,z;
};
int main() {
struct Number n1 = {1,2,3};
struct Number n2 = n1;
printf("%d\n",n1.y);
printf("%d",n2.y);
return 0;
}
Output is 2 for both cases.
0
That simple assignment used and when entering the function did not give me, just as capable somewhere can give me error, so I will try that code separately, but it was to know if it could. Thank you!
0
#include <iostream>
using namespace std;
int main() {
int A;
cout<<"Please Enter your choice : ";cin>>A;
switch (A){
case 1:{ int r;
int c;
cout<<"please Enter number of rows : ";cin>>r;
cout<<"Please Enter number of colums : ";cin>>c;
for(int j = 0;j <= r-1;j++){
cout << "\n*";
for(int k = 0;k <= c-2;k++){
cout << " * ";}
}
break;
}
case 2:{
int r;
cout << "Enter number of rows: ";
cin >>r;
for(int i = 1; i <= r; ++i) {
for(int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << "\n";
}
break;
}
case 3:{
int r;
cout << "Enter number of rows: ";
cin >> r;
for(int i = r; i < 1; ++i) {
for(int space = 0; space < r-i; ++space)
cout << " ";
for(int j = i; j <= 2*i-1; ++j)
cout << "* ";
for(int j = 0; j >= i-1; --j)
cout << "* ";
cout << endl;
}
break;
}
}
return 0;
}