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.
CODE:
#include<stdio.h>
#include <stdlib.h>
int R_get_int(){
int n;
printf("Enter a positive number: ");
//taking user input number
scanf("%d",&n);
//checking given number is positive or not
if(n>0){
//if it positive return that to
main
printf("Thank you!!\n");
return n;
}
else{
//if negative warn user and again
call this function
printf("Please enter positive
number.\n");
R_get_int();
}
}
int R_pow(int base, int ex){
//if exponentia is 0 then value is 1
if(ex==0)
return 1;
else
return base*R_pow(base,ex-1);
//multiply result with base for
each time
}
void R_Jarvis(int start){
printf("%d ",start);
//if sequence reaches 1 then stop process
if(start==1)
printf("\n");
//if it is even call it with its half
else if(start%2==0)
R_Jarvis(start/2);
//if it is odd multiply with 3 and add 1
else
R_Jarvis(start*3+1);
}
void R_fill_array(int array[],int len){
//for pointing index use static variable
static index=0;
//if index reaches ens stop calling function
if(index==len)
return;
else{
//genaraing random numners
int rnd = (rand() % (320 + 1 - 7))
+ 7;
//store the random numbers to the
array
array[index++]=rnd;
printf("%d ",rnd);
R_fill_array(array,len);
}
}
void R_prt_array(int array[],int len){
//for pointing index use static variable
static index=0;
//if index reaches ens stop calling function and print
last value
if(index==len-1)
printf("%d",array[index]);
else{
//print each element
printf("%d ,
",array[index++]);
R_prt_array(array,len);
}
}
void R_copy_back(int from[],int to[],int len){
//for pointing index use static variable
static index=0;
if(index==len)
return;
//coping the elements
to[index]=from[len-index-1];
printf("%d ",to[index++]);
R_copy_back(from,to,len);
}
int R_count_num(int num,int array[],int len){
static index=0,count=0;
//if index reaches ens stop calling and return
count
if(index==len)
return count;
//for occurence increases the count
if(array[index++]==num)
count++;
R_count_num(num,array,len);
}
int main(){
int array[5],to[5];
printf("Function1:\n");
printf("Function1 returns %d\n",R_get_int());
printf("\nFunction2:\n");
printf("5 power 3 is %d\n",R_pow(5,3));
printf("\nFunction3:\n");
printf("Jarvis sequence for 15 is: ");
R_Jarvis(15);
printf("\nFunction4:\nArray elements are: ");
R_fill_array(array,5);
printf("\n\nFunction5:\nArray elements are: ");
R_prt_array(array,5);
printf("\n\nFunction6:\ncopied Array elements are:
");
R_copy_back(array,to,5);
printf("\n\nFunction7:\n22 occurs %d times in the
array.",R_count_num(22,array,5));
}
OUTPUT:
PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...
LANGUAGE IS C++ Lab Ch14 Recursion In this lab, you are provided with startup code which has six working functions that use looping (for, while, or do loops) to repeat the same set of statements multiple times. You will create six equivalent functions that use recursion instead of looping. Although looping and recursion can be interchanged, for many problems, recursion is easier and more elegant. Like loops, recursion must ALWAYS contain a condition; otherwise, you have an infinite recursion (or...
Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...
I need help writing these functions in C programming. Write a C function that checks if an array is sorted or not using an iterative approach. Write a C function that checks if an array is sorted or not using a recursive approach Write a C function to reverse the elements of an array. Note you are not allowed to use an 1. additional array to do that Write a C function to find the sum of the elements of...
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...
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,...
code in c please Concepts to Practice User-written functions math.h Description For the prelab assignment, you are to write a function to calculate Power (exponentiation). Your function will be called MyPower. MyPower() will raise a given double type number to a positive integer power. You may NOT call any function from math.h such as pow) in your implementation of MyPower) The main) function in your program should look exactly like this: int main(void) int i,j; for (i-1;i<5;i++) { for (j-1;j<5;j++)...
Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...
C++ Using Recursion We are going to create a (looping) menu that accesses functions that use recursion. The function headers and a description will be provided. You are responsible for defining the functions. Ensure that they each contain a base case they reach that doesn’t have a recursive function call, otherwise it’s an infinite loop! Functions must be implemented with recursion. int Factorial(int arg) Returns arg! (4! Is 4 * 3 * 2 = 24) Base case is Factorial(1) returning...
4. Consider the following (almost) complete program: 4includeciostream> using namespace std: la)prototypes here. int main () const int size 6 int alsize] 15, 2, 3, 1, 13, 8): int p pma+1 show (a, size) mystery (a, size); show (a, aize) cout<<a [2]+a(51<<endl; cout<<(a+2)-3<<endl: cout<<tp+ a<<endl; cout<<at5<cendl void show (int all, int n) 17 (b) define show void mystery (int all, int n) int temp Eor (int i-0 i<n/2 i++) temp aij alil-aln-i-117 a [n-i-11 temp a) Write prototypes for the...
must be done in C You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...