Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please need help in C programming CODE for the following: NOTE: It is one questi

ID: 3733353 • Letter: P

Question

Please need help in C programming CODE for the following:

NOTE: It is one question with sub-questions (in sequence, sub-questions should have been in alphabetical or Roman numeral order), I am exremely sorry for the inconvenience.

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

4. If we have individual arrays for each element
   array for Names - Name- It contains Oxygen, Carbon..
   array for Symbol - Symbol- It contains O,C....
   array for Number - Number- It contains 8,6....
   array for Weight - Weight- It contains 15.99,12.011....

   In this case we can have following code to display the
   information pertaining to oxygen as follows:

   int i;
   for (i = 0; i<5; i++){
      if (strcmp(Name[i],"Oxygen") == 0){
         printf("%s %c %d %.3f ", Name[i],Symbol[i],Number[i], Weight[i]);
      }
   }

5.
   int i;
   for (i = 0; i<5; i++){
       printf("%s %c %d %.3f ", Name[i],Symbol[i],Number[i], Weight[i]);
   }

6.
   double max = Weight[0];
   int index = 0;
   int i;
   for (i = 0; i<5; i++){
      if (Weight[i] > max){
          max = Weight[i];
          index = i;
      }
      
   }
   printf("%s %.3f ", Name[index], Weight[index]);

7.
double sum = 0;
int i;
   for (i = 0; i<5; i++){
        sum = sum + Weight[i];
   }
double avg = sum/5;

8.
char ch[2];
char matrixA[5];
int i;
for (i = 0; i<5; i++){
      scanf("%s", ch);
      matrixA[5] = ch[0];
}
for (i = 0; i<5; i++){
      printf("%c ", matrixA[i])
}

9. int matrixB[2][3] = {{3,5,2},{4,1,7}};
10.
    int i,j;
    for (i = 0; i<2; i++){
      for (j = 0; j<3; j++){
          printf("%d ", matrixB[i][j]);
      }
      printf(" ");
    }

11.
    int i,j;
    for (i = 0; i<2; i++){
      for (j = 0; j<3; j++){
          printf("Enter a value:");
          scanf("%d", &matrixB[i][j]);
      }
    
    }

12. char names[3][20] = { "John", "Ram", "Mary"};

13.

   strcpy(names[0], "nickname1");
   strcpy(names[1], "nickname2");
   strcpy(names[2], "nickname3");
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote