Question

In: Computer Science

Counting integers greater than 10 Write the pseudo-code for a brute force approach to counting the...

Counting integers greater than 10

  1. Write the pseudo-code for a brute force approach to counting the number of integers greater than 10 in an array of n integers.

  1. Write the pseudo-code divide-and-conquer algorithm for counting the number of integers greater than 10 in an array of n integers.

  1. Give the recurrence relation for the number of comparisons in your divide-and-conquer algorithm in part b.  

Solutions

Expert Solution

#include<stdio.h>
#include<conio.h>
main(){
   int a[100],n;
   int i=0,count=0;
   printf("Enter the size of array ");//takes input the size of array
   scanf("%d",&n);
   printf(" \n Enter the data\n");
   for(i=0;i<n;i++){
       scanf("%d",&a[i]);
   }
   i=0;
   while(a[i]!=NULL){
       if(a[i]>10){
           count=count+1;

//here it checks the condtion for every element if the element greater than 10 then count will be increased
       }
           i++;
       }
   printf("\n The number of elements greater than 10 are %d ",count);
}

Thank you.


Related Solutions

Counting evens Write the pseudo-code for a brute force approach to counting the number of even...
Counting evens Write the pseudo-code for a brute force approach to counting the number of even integers in an array of n integers. Write the pseudo-code divide-and-conquer algorithm for counting the number of even integers in an array of n integers. Give the recurrence relation for the number of additions in your divide-and-conquer algorithm.  
String search   Describe the brute force solution to counting the number of times the letter “a”...
String search   Describe the brute force solution to counting the number of times the letter “a” occurs in a text. Outline a divide-and-conquer algorithm for counting the number of times the letter “a” occurs in a text. Analyze each approach and compare the efficiencies.
Write out the “brute-force” (exact) expressions for force and torque on a loop 1 in the...
Write out the “brute-force” (exact) expressions for force and torque on a loop 1 in the magnetic field B of loop 2. Write these expressions using magnetic moment of loop 1. Pay attention to the r, r’, … vectors. A magnet (magnetic dipole) tends to align itself parallel to external field. If the magnetic moment is 5 [CGS units] in -z direction and magnetic field is 25 [CGS units] in z direction. What is the value of the torque? Plot...
Given two integers, start and end, where end is greater than start, write a recursive C++...
Given two integers, start and end, where end is greater than start, write a recursive C++ function that returns the sum of the integers from start through end, inclusive.Example: If start is 5 and end is 10 then the function will return: 45 which is sum of 5, 6, 7, 8, 9, and 10. int sum (int start, int end){
Synchronize producer and consumer threads that use 10-item buffer for communication. Write pseudo code for both...
Synchronize producer and consumer threads that use 10-item buffer for communication. Write pseudo code for both threads. Assume that you can use void Buffer::store(Item item) and Item Buffer::get() methods, but you need to explicitly ensure that you never store more than 10 items in the buffer (to prevent overflow).
write a method that returns the index of the second smallest element in an array of integers. If the number of such elements is greater than 1.
write a method that returns the index of the second smallest element in an array of integers. If the number of such elements is greater than 1. return the second smallest index. Use the following header:public static int index of seconds sma11eststenent tint array
A customer in a grocery store is purchasing three items. Write the pseudo code that will:...
A customer in a grocery store is purchasing three items. Write the pseudo code that will: • Ask the user to enter the name of the first item purchased. Then ask the user to enter the cost of the first item purchased. Make your program user friendly. If the user says the first item purchased is milk, then ask: “What is the cost of milk.” [This should work no matter what item is entered by the user. I might buy...
Write psuedocode to brute-force a simple password engine. Then, offer advice on making passwords more secure...
Write psuedocode to brute-force a simple password engine. Then, offer advice on making passwords more secure to brute-force attacks.
Research an historical example of inflation (greater than 10% in the US or greater than 15%...
Research an historical example of inflation (greater than 10% in the US or greater than 15% in any other country): Summarize the time-frame, duration and rate of inflation Analyze the root causes of the inflation Describe interest rates during the inflationary period Describe the major economic consequences of the inflation Explain how they were able to control the inflation (if they were)
Research an historical example of inflation (greater than 10% in the US or greater than 15%...
Research an historical example of inflation (greater than 10% in the US or greater than 15% in any other country): Summarize the time-frame, duration and rate of inflation Analyze the root causes of the inflation Describe interest rates during the inflationary period Describe the major economic consequences of the inflation Explain how they were able to control the inflation (if they were)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT