Please need help in C programming CODE of the following: 1. Which of the followi
ID: 3733165 • Letter: P
Question
Please need help in C programming CODE of the following:
1. Which of the following is a valid C statement? Explain what each valid statement does. For invalid statements, explain the problem.
a. int items [ 5 ];
b. int items [ ];
c. int items = { 3, 7, 2 };
d. int items [ ] = { 3, 7, 2 };
e. int items [3] = { 3, 7, 2 };
2. Write a C statement that will create an integer array named nums, of length 3. Show two ways to initialize all the elements in the array to 10. One of the ways should use a for-loop.
3. Write C statements to create 3 separate arrays containing information for the elements below. Name the arrays symbols, numbers, and weights.
Name Symbol Number Weight
a. Oxygen O 8 15.999
b. Carbon C 6 12.011
c. Nitrogen N 7 14.007
d. Fluorine F 9 18.998
e. Boron B 5 10.81
4. Write the code to display all of the information saved in the arrays for just Oxygen.
5. Using a for-loop, write the code to display the symbols, numbers, and weights for all of the elements above, one element per line.
6. Write the code to locate and print the name and weight of the heaviest element.
7. Write the code to calculate and display the average weight of all the elements.
8. Define a 1-D array named matrixA of length 5. Use iteration to prompt the user to enter one single character at a time and save them in the array. Use iteration to display the characters stored, one per line.
9. Define a 2-D array named matrixB that contains the following values:
3 5 2
4 1 7
10. Use iteration to display all the values in the order shown.
11. Use iteration to prompt the user to enter a new value for each position. Read in each new value and assign it in the correct position.
12. Define an array called names that that contains the names of 3 of your friends.
13. Reassign the names in the array above to be appropriate nicknames for the friends.
Thank you.
Explanation / Answer
%we are supposed to do 1 question at a time, i have done 4, please ask remaining again
a. int items [ 5 ];
b. int items [ ];
this is invalid as array size is needed
c. int items = { 3, 7, 2 };
this is invalid as items should be array and not a variable
correct would be int items[]={3,7,2};
d. int items [ ] = { 3, 7, 2 };
this is valid
e. int items [3] = { 3, 7, 2 };
this is valid
===============================================
2)
statement to create array:
int nums[3];
1st way of initializing:
nums[]={10,10,10};
2nd way:
int i;
for(i=0;i<3;i++)
nums[i]=10;
===============================================
3)
char symbol[]={'O','C','N','F','B'};
int numbers[]={8,6,7,9,5};
float weights[]={15.999,12.011,14.007,18.998,10.81};
===============================================
4)printf("Symbol:%c Number:%d Weight:%f",symbol[0],numbers[0],weights[0]);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.