Question

15.6: Fix the code to print the count from 1 to x (to loop x times)...

15.6: Fix the code to print the count from 1 to x (to loop x times)

#include <iostream> // include the header file

using namespace std;

void count(int x){
  
for(int i=1; i<=x; i++){
cout<<x;
}
}

int main(){
  
int x,i;
  
cin >> x;
count(x);
  
return 0;
}

15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x"

#include <iostream> // include the header file

using namespace std;

int main(){
  
int x;
cin >>x;
for(int i=1; i<=x; i++)
for(int j=1; j<=x; j++)
cout<<x;
  
return 0;
}

16.4 Fix the code to print the last element of the array

#include <iostream>

using namespace std;

int main(){
  
int array[7]; // an array of size 7
int x=0;
cin >> x;
for(int i = 0 ; i < 7; i++){ // array initialization
array[i] = x;
  
}

20.6 make both pointers point at the same variable then use use one of the pointers to change it

#include <iostream>

using namespace std;
//make both pointers point at the same variable
//then use use one of the pointers to change it


int main(){
int i;
cin >> i;
cout << i << endl;
int * p;
int * q;
  
//get user input for i using one of the pointers
  
cout << *q << endl;
cout << *p << endl;
cout << (p == q) << endl;
}

  
cout << "The last element is: "<<x;
  
return 0;
}
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream> // include the header file

using namespace std;

void count(int x){
  
for(int i=1; i<=x; i++){
cout<<i<<" ";
}
}

int main(){
  
int x,i;
  
cin >> x;
count(x);
  
return 0;
}

========================================

#include <iostream> // include the header file

using namespace std;

int main(){
  
int x;
cin >>x;
for(int i=1; i<=x; i++)
cout<<x;
for(int j=1; j<=x; j++)
cout<<x;
  
return 0;
}

========================================

#include <iostream>

using namespace std;

int main(){
  
int array[7]; // an array of size 7
int x=0;
cin >> x;
for(int i = 0 ; i < 7; i++){ // array initialization
array[i] = x;  
}
cout<<array[6];
return 0;
}

========================================

#include <iostream>

using namespace std;
//make both pointers point at the same variable
//then use use one of the pointers to change it


int main(){
int i;
cin >> i;
cout << i << endl;
int * p;
int * q;
  
p = q;
  
cout << *q << endl;
cout << *p << endl;
cout << (p == q) << endl;
}

  
cout << "The last element is: "<<x;
  
return 0;
}
Add a comment
Know the answer?
Add Answer to:
15.6: Fix the code to print the count from 1 to x (to loop x times)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT