Question

C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C...

C programming!!C programming!!C programming!!C programming!!C programming!!

C programming!!C programming!!C programming!!C programming!!C programming!!

C programming!!C programming!!C programming!!C programming!!C programming!!

Q2 (20 marks):  remembering state, conditions, functions

Write a function that takes two arguments an array and the size of the array and returns  a count of all of the numbers between 2 and 5 inclusive.

The code below shows how your function will be called.

 

int main(void) {

    int values[6]={1,2,4,5,3,6};
    int size=6;

    printf("There are %d values between 2 and 5 (inclusive)\n", count_values_between_2_5(values, size));
}
When run with the above main code, the sample output would be:

There are 4 values between 2 and 5 (inclusive)
Submit your solution as q2.c
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int count_values_between_2_5(int values[], int size){
   int count = 0;
   for (int i = 0 ; i < size ; i++){
       if (values[i] >= 2 && values[i] <= 5){
           count++;
       }
   }
   return count;
};

int main()
{
   int values[6]={1,2,4,5,3,6};
   int size=6;
   printf("There are %d values between 2 and 5 (inclusive)\n", count_values_between_2_5(values, size));
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C...
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
  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • 4 Exercise: Arrays and Functions Many of the tasks from the previous exercises can be generalized...

    4 Exercise: Arrays and Functions Many of the tasks from the previous exercises can be generalized to functions, allowing easy reuse. Recall that arrays in C are essentially represented by pointers, so when an array is passed into a function, the function is given access to the original array data (not a copy). This means that arrays are effectively passed by reference in C, and therefore that functions must be careful not to modify the contents of arrays they receive...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • C PROGRAM The following is code prints the current activation record number, the memory address of...

    C PROGRAM The following is code prints the current activation record number, the memory address of the current array, followed by the estimated size of the current activation record as a distance between the current array address and the array address from the previous activation record. I need it to run until a segmentation fault occurs and also it must print the estimated size of the runtime stack as a product of the size of current activation record and the...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • I need help making my array into a function that can called by the main function...

    I need help making my array into a function that can called by the main function using my program. This is C programming int prime (int x) { int i; i = 2; while (i < x) { if (x % i == 0) return 0; i++; } return 1; } int main (void){ int n; scanf ("%d", &n); if (n < 1) { printf ("Error: at least one data value must be provided.\n"); return 1; } int a[n]; int...

  • Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you...

    Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...

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