Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the int main(void) function as a driver program and call the above three functions result with sample Input/Output 1) Program: #include #include int power(int,

Write the

int main(void)

function as a driver program and call the above

three

functions result with

sample Input/Output

1) Program:

#include #include int power(int, int); int main(void) { int x, n; printf("Enter a number and powerto raise it to: "); scanf("%d %d", &x, &n); // Here we are scanning user inputs printf("Result: %d ", power(n, x)); // Here we are printing the Result return 0; } int power(int x, int n) { int m; if (n == 0) return 1; if (n % 2 == 0) { m = power(x, n / 2); return m * m; // Here we are returning the power value to the main function } else return x * power(x, n - 1); // Here we are returning the power value to the main }

Output:

Enter a number and powerto raise it to: 3 2

Result: 8

2) Program:

#include int hcf(int n1, int n2); int main() { int n1, n2; printf("Enter any two positive integers: "); scanf("%d %d", &n1, &n2); printf("Greatest Common Divisor of %d and %d is %d.", n1, n2, hcf(n1,n2)); return 0; } int hcf(int n1, int n2) { if (n2 != 0) return hcf(n2, n1%n2); // Here we are returning the hcf value to the main function else return n1; // Here we are returning the n1 value to the main function }

Output:

Enter any two positive integers: 3 2

Greatest Common Divisor of 3 and 2 is 1.

3) Program:

#include int main() { int array[100], minimum, size, c, location = 1; // Here we are mentioning maximum size of an array printf("Enter the number of elements in array "); scanf("%d",&size); printf("Enter %d integers ", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is %d", minimum); return 0; }

Output:

Enter the number of elements in array 4 Enter 4 integers 0 -1 2 3 Minimum element is -1

Expert Answer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions