Question

Write a program that uses a two-dimensional array to store daily minutes walked and protein intake...

Write a program that uses a two-dimensional array to store daily minutes walked and protein intake for a week. Prompt the user for 7 days of minutes exercise and protein intake; store in the array. Write a bubble sort to report out the sorted minutes walked values -lowest to highest. Write another to report out the sorted protein intake - highest to lowest. Your program should output all the values stored in the array and then output the 2 sorted outputs.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

void swap(int *a, int *b);
void bubbleSort(int arr[], int n);

int main(){
   int i,j;
   int A[7][2];
   int temp_1[7];
   int temp_2[7];
  
   printf("Enter the minutes walked and protien intake in a week: \n");
  
   for(i = 0; i < 7; i ++){
       for(j = 0; j < 2; j ++){
           scanf("%d",&A[i][j]);
       }
   }
  
   printf("\nThe data entered is : \n");
  
   for(i = 0; i < 7; i ++){
       printf("Number of minutes walked and protien intake on day %d is : ",i+1);
       for(j = 0; j < 2; j ++){
           printf("%d ",A[i][j]);
       }
       printf("\n");
   }
  
   for(i = 0; i < 7; i ++){
       temp_1[i] = A[i][0];
   }
  
   for(i = 0; i < 7; i ++){
       temp_2[i] = A[i][1];
   }
  
   bubbleSort(temp_1, 7);
   bubbleSort(temp_2, 7);
  
   printf("\nThe sorted output is : \n");
  
   printf("\nThe sorted data of minutes walked is : \n");
  
   for(i = 0; i < 7; i++){
       printf("%d ", temp_1[i]);
   }
  
   printf("\n\nThe sorted data of protien intake is : \n");
  
   for(i = 6; i >= 0; i-- ){
       printf("%d ", temp_2[i]);
   }
  
   return 0;
}


void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
  
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)   
  
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}

For help please comment.
Thank You.

Add a comment
Know the answer?
Add Answer to:
Write a program that uses a two-dimensional array to store daily minutes walked and protein intake...
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
  • IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and...

    IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array.   Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code.   Your program should output...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Write a program that uses an int one-dimensional array list to input 10 integers representing amounts...

    Write a program that uses an int one-dimensional array list to input 10 integers representing amounts of money. Find the highest (maximum) amount and the lowest (minimum) amount. Output all the amounts and their difference to the highest amount side by side as shown in the sample output. c++ Chapter #8 (Arrays) and 6 (Value Returning and void Functions) Exercise #1: One-dimensional array manipulation Write a program that uses an int one-dimensional array list to input 10 integers representing amounts...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

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