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...
•Write a Write a Python script that performs brute force to extract a password protected zip...
•Write a Write a Python script that performs brute force to extract a password protected zip file named sec3.zip. The password is believed to be associated with one of the dictionary words in the 'wordlist.txt file. The password policy enforces that all employees MUST use passwords that include at least one capital and one digit. The files are attached (hint must import zipfile)
Write a python program that implements a Brute Force attack on Shift Cipher. In this program...
Write a python program that implements a Brute Force attack on Shift Cipher. In this program there is only one input - ciphertext - is a sequence of UPPER CASE letters. To make it easy, the program will be interactive and will output all possible plaintexts and ask user which plaintext makes sense. As soon as user will decide YES, the program will stop searching and print the desired plaintext and the found SHIFT KEY.
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){
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
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 Python script that performs brute force to extract a password protected zip file named...
Write a Python script that performs brute force to extract a password protected zip file named sec2.zip. The password is believed to be associated with one of the dictionary word in the 'wordlist.txt file. a) Paste your code here b) What is the password?
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT