Can someone help me write a small clean "helper" function which accepts two arguements, finds the greatest common divisor, and returns it? DO NOT use recursion. This is to be written in C++. I would be greatful if you wrote a small driver main() to test it as well.
Thanks in advance.
#include <stdio.h>
int gcd(int n1, int n2);
int helper(int n1, int n2);
int main()
{
int n1, n2;
printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("GCD of %d and %d is %d.", n1, n2, gcd(n1,n2));
return 0;
}
int gcd(int n1, int n2)
{
if (n2 != 0)
return helper(n1,n2);
else
return n1;
}
int helper(int n1, int n2)
{
return gcd(n2, n1%n2);
}
Can someone help me write a small clean "helper" function which accepts two arguements, finds the...
Can someone help me with the following problems please! 6. Write a function that accepts a text file’s name and returns a. The number of uppercase letters in the file b. The number of lowercase letters in the file c. The number of digits in the file d. The number of whitespace characters in the file .
I need help writing this program in C++. Thanks so much for your
help in advance
Function 1:
Write a function that accepts an integer argument and returns
the sum of all the integers from 1 up to the number passed as an
argument. For example, if 50 is passed as an argument, the function
will return the sum of 1, 2, 3, 4, ... 50. Use recursion to
calculate the sum. Demonstrate the function in a
program.
A sample...
Please help me with this python3 assignment. Write an iterative function, count_consonants(), that accepts a string (that can include upper and lowercase characters) and returns the number of consonants in that string. A consonant is defined as any letter in the English alphabet other than the vowels a, e, i, o, u. For example, if you call the function as follows: count_consonants('correct horse battery staple') the function should return 20.
can someone please help me with this. I need to use
java.
Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...
can somebody help me with this exercise 5 Euclidean algorithm The largest common divisor (gcd) of two positive integers p and q can be given by the Euclid's algorithm explained in the lecture will be determined. · Write a function gcdIterative that uses the largest common divisor of p and q Calculates loop structure and returns. Use the pseudocode given in the lecture as a starting point and implement it as directly as possible into a C ++ program. Use...
can someone help me solve this question? Thanks in
advance!!
Each week a retail outlet accepts delivery of a certain item from 3 different suppliers A, B and C. All the items received are put into an empty bin. A supplies 50% of these items, while B and C each supply 25%. From past experience, it is known that 2% of the items supplied by A are defective, 2% of the items supplied by B are defective and 4% of...
can someone help me fix this. The function that finds the minimum and maximum values of the array and outputs the value and index doesnt find the maximum value of the array. #include <iostream> #include <fstream> #include<iomanip> using namespace std; void readArray(ifstream& inF, int arr[], int&ArrSize); void writeArray(ofstream & outF, int arr[], int & ArrSize); void MaxAndMin(ofstream & outF, int arr[], int & ArrSize, int &high, int &low); int main() { int arr[100]; int i = 0; ...
Can someone help me understand this step by step (C++)
Array Shifter and Array Reversal Write a function that accepts an array of doubles and the array's size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array...
Can someone help me with a simple C programming problem? How do I make some code like this into its own function? Currently it's pat of the main function, but I want to be able to call it. If you could help me with the prototype, function call, and definition, I'd really appreciate it. Thanks! if(some_input=='r'){ someone = 0; } else if(some_input=='p'){ someone = 1; } else if(some_input=='s'){ someone = 2; } else if(some_input=='q' || some_input=='Q'){ break; // Breaks...
can someone please help me write an email for my teacher asking her to proofread my essay. I was starting to write her an email but I feel like I don't make sense or sounds polite enough. English isn't my first language and I don't feel very confident about it. Thank you in advance for your help!