Complete the function function has three parameters

Assignment Help Programming Languages
Reference no: EM13763670

1: Complete the function: func in the following program. This function has three parameters: The first and second parameters are of type: int. The third one is a function that has two parameters of type: int and returns a value of type: int. In the body of function call its third parameter (which is a function) passing the first and second parameter of: func.

#include <stdio.h>

int pow(int m, int n){

  int i, ans = 1;

  for(i = 1; i <= n; i++)

    ans = ans * m;

  return ans;

}

int max(int m, int n){

  if(m > n)

    return m;

  return n;

}

int min(int m, int n){

  if(m < n)

    return m;

  return n;

}

//Complete the following function

void func (//Complete){

//Complete

}

void main (){

  // This function is complete. Do not change it.

  int x, y;

  printf("Enter two positive integers: ");

  scanf("%d%d", &x, &y);

  func(x, y, pow);

  func(x, y, max);

  func(x, y, min);

}

Sample dialog:

Enter two positive integers: 2 3

8

3

2

Note: Your program should work for any positive integer.

2: Complete the function: total. This function has one or more parameters of type: int. This function returns the sum of all its parameters.

Note: Always we add argument zero as the last argument. This argument acts as a flag.

#include <stdio.h>

#include <stdarg.h>

int total(int arg, ...){

  // Complete the body of this function. Do not change:

  // int total(int arg, ...)

}

void main(){

  // This function is complete. Do not change it.

  int a, b, c, d, e;

  printf("Enter 5 non-zero integers: \n");

  scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);

  printf("%d\n", total(a, b, c, d, e, 0));

  printf("%d\n", total(a, b, c, d, 0));

  printf("%d\n", total(a, b, c, 0));

  printf("%d\n", total(a, b, 0));

}

Sample dialog:

Enter 5 non-zero integers:

22 -2 30 5 -10

45

55

50

20

Note: Your program should work for any non-zero integer.

3: Complete the following program using linked list of nodes of type the struct below to simulate a stack of integers. In a stack an integer goes on the top and removed from the top of the stack.

Note:

Each node in the stuck (linked list) must be of type: Rec.

The variable: top must refer to top of the stack.

Use the variable: freeNode to either create a new node or to take a node from top of the stack.

#include <stdio.h>

#include <stdlib.h>

typedef struct Node{

  // This struct is complete. Do not change it.

  int num;

  struct Node *next;

} Rec;

void main(){

  // Complete this function

  Rec *top, *freeNode;

  int x;

  top = NULL;

}

Sample dialog:

Enter 1 to push a number, 2 to pop, and 3 to quit: 2

The stack is empty.

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: 33

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: -15

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: 45

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: -9

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: 88

Enter 1 to push a number, 2 to pop, 3 to quit: 2

88

Enter 1 to push a number, 2 to pop, 3 to quit: 2

-9

Enter 1 to push a number, 2 to pop, 3 to quit: 1

Enter an integer to push: 100

Enter 1 to push a number, 2 to pop, 3 to quit: 3

Note: Your program should work for any integer.

Below I show the stack for the above dialog sample.

 

Empty stack

33

After pushing: 33

-15

33

After pushing: -15

45

-15

33

After pushing: 45

-9

45

-15

33

After pushing: 45

88

-9

45

-15

33

After pushing: 88

-9

45

-15

33

After popping

45

-15

33

After popping

100

45

-15

33

After pushing:100

Reference no: EM13763670

Questions Cloud

Important characteristics of an effective paralegal : It is widely known that utilizing paralegals is a frequent concern for practicing attorneys, especially when a paralegal's actions may leave them performing tasks, Determine three (3) most important characteristics of an effective paralegal. Justif..
How the manager could have handled the situation : Analyze a minimum of three outside sources from the Internet that are reliable and deal with nonverbal communication that a manager could use in order to improve his or her active listening skills and body language in conversations such as you dis..
Differences between the two engagements : What is one assurance engagement and one attestation engagement other than an audit of financial statements? What are the differences between the two engagements?
How a competitor is positioned in the environment : Complete a SWOT analysis for the selected industry. The SWOT analysis allows a business to understand how a competitor is positioned in the environment by assessing its strengths.
Complete the function function has three parameters : Complete the function: func in the following program. This function has three parameters: The first and second parameters are of type: int. The third one is a function that has two parameters of type: int and returns a value of type: int.
What did you learn about how and why false confessions occur : One of the most confusing aspects of wrongful convictions is the concept of false confessions. What did you learn about how and why false confessions occur
Purpose of engagement planning : What is the purpose of engagement planning? What critical information should the auditor consider during engagement planning? How will this information affect the scope of the audit?
Why observers have argued that the worlds gdp statistics : why do you think observers have argued that the world's gdp statistics would be more believable if private companies tabulated the data?
Quick fast car care application : Quick Fast Car Care is a small business that specializes in oil changes and car washes. Their strategic advantage is providing quick service. To provide quick service, this owner wants a new application that will calculate services provided to cus..

Reviews

Write a Review

Programming Languages Questions & Answers

  Estimate the storage space for telephone book

Estimate the storage space (number of bytes) required for each of the following items: A telephone book with 10,000 entries consisting of names, addresses and phone numbers. Use your phone book to estimate the average length of an entry.

  Create class uses element array of digits to store integers

Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods input, output, add and subtract.

  Provide a complete program that performs substitution cipher

Provide a complete program that performs a simple substitution cipher. The program should take plain text and a shift value and produce the encrypted text. Then it should take encrypted text and a shift value and produce the plain text once again.

  Write a machine-language program

Write a machine-language program to input two one-digit numbers add them, and output the one-digit sum. Write it in a format suitable for the loader and execute it on the Pep/8 simulator.

  Write program using while loop to output squares of integers

Write a program that uses while loop to perform the following steps:Output the sum of all the even numbers between firstnum and secondnum inclusive. Output all the numbers and their squares between firstnum and secondnum inclusive.

  Create a macro that multiplies

Create a macro named mMult32 that multiplies two unsigned 32-bit memory operands and produces a 32-bit product.

  Program to read sales amount-calculate sales commissions

Write down the program to read the sales amount and calculates sales commissions using following scheme.

  Use a switch statement to calculate a letter grade

Use a switch statement to calculate a letter grade based on a numeric average up to 100. Allow the numeric score to be entered in a text field. A Grade button will display the corresponding letter grade in a label.

  Copies the content of one file into another file

write a c program that copies the contents of one file to a destination file.

  Display information about users that are currently logged in

Create a new file titled TestWork.scr Change the permissions on this new file to add the execute bit for user, group, and owner. Edit your new file using Gedit or VI and change it so it performs the following actions:

  Nested if functions along with vlookup function

The Vlookup function returns a #n/a! error if no lookup value is supplied, and various other errors whne invalid keys are entered. Use a combination of three levels of nested if functions, and other functions to avoid these problems.

  Use the linked stack class to support

Use the Linked stack class to support an application that tracks the status of an online auction. Budding begins at 1(dollars, pounds, euros, or whatever) and proceeds in increments of at least 1

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd