QUESTION 1 What is the index number of the last component in
QUESTION 1
What is the index number of the last component in the array numList above?
int numList[50];
for (int i = 0; i < 50; i++)
numList[i] = 2 * i;
numList[10] = -20;
numList[30] = 8;
0
49
30
50
QUESTION 2
What is the value of numList length (size) in the last question?
0
49
30
50
QUESTION 3
Consider the following statements:
int hits[] = {5, 7, 9, 11, 13, 15};
What is the number of elements in the array hits.
0
6
5
15
QUESTION 4
Complete the following C++ program that prints the content of a string in the reverse order
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[] = “CSE 100 Fall 2014”;
/* To Do: Select a for loop that prints the content of the string in the reverse order
Hint: you can use strlen( const char* ) function to get the length of the string
Ex. char str[] = \"Cat\"; int length; length = strlen(str); length gets 3.
*/
return 0;
}
int i, length;
length = strlen(str);
for(i=0;i<length;i++){
cout<<str[i];
}
cout<<endl;
int i, length;
length = strlen(str);
for(i=length-1;i>=0;i--){
cout<<str[i];
}
cout<<endl;
int i, length;
length = strlen(str);
for(i=length-1;i>=0;i++){
cout<<str[i];
}
cout<<endl;
int i, length;
length = strlen(str);
for(i=length;i>0;i--){
cout<<str[i];
}
cout<<endl;
| 0 | ||
| 49 | ||
| 30 | ||
| 50 |
Solution
Ans)
Question 1) 49
Indexing of array starts from 0,1,2,3 ...so on,So for a array size of 50 the index count is from 0 to 49
so the index number of last component in the array numList is 49
----------------------------------
Question2) 50
The array size is no of element it can store or no of memory locations ,as numlist is defined as numList[50]
it can store 50 elements ,so its size is 50
-----------------------------------------
Question3) 6
Count the no of elements starting from 1 and there are 6 elements
Only 1question per post will be answered but I answerd 3 here
![QUESTION 1 What is the index number of the last component in the array numList above? int numList[50]; for (int i = 0; i < 50; i++) numList[i] = 2 * i; numLi QUESTION 1 What is the index number of the last component in the array numList above? int numList[50]; for (int i = 0; i < 50; i++) numList[i] = 2 * i; numLi](/WebImages/2/question-1-what-is-the-index-number-of-the-last-component-in-973584-1761496544-0.webp)
![QUESTION 1 What is the index number of the last component in the array numList above? int numList[50]; for (int i = 0; i < 50; i++) numList[i] = 2 * i; numLi QUESTION 1 What is the index number of the last component in the array numList above? int numList[50]; for (int i = 0; i < 50; i++) numList[i] = 2 * i; numLi](/WebImages/2/question-1-what-is-the-index-number-of-the-last-component-in-973584-1761496544-1.webp)