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

  Program to read employee information into array of objects

Consider a program that will read employee information into an array of objects, sort the array by employee identification number, write out the sorted array.

  Write class to hold hourly rate of pay

Write down the class which comprises variables which hold your hourly rate of pay and number of hours that you worked. Illustrate your gross pay.

  Research on programmer defined functions

Write a 2 page research paper (excluding title and reference pages) on programmer-defined functions. Explain the concepts discussed in the textbook using at least an example not included in the textbook.

  Create class to calculate perimeter and area rectangle

Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle.

  Explain the interaction framework

Explain the Interaction Framework discussed by Steven Heim (2008). Choose a computing device (like an ATM machine or the self-check-out at a grocery store

  Write function to take the name of file as one parameter

Write a function named paragraphStats() that takes one parameter:the name of a file. The file contains a single line of text.

  Write program to clear the screen and locate the cursor

Write a program that clears the screen, locates the cursor near the middle of the screen, prompts the user for two integers, adds the integers.

  Write down program which permits to play tic tac toe game

Write down the program which permits 2 players to play tic tac toe game. Program should contain class tictactoe to implement tictactoe object.

  Write program to enter last names of five candidates

Write down the program which permits the user to enter last names of five candidates in local election and number of votes received by each candidate.

  Write a statement that prints the message recall

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear - Write a statement that prints the message "Recall" to standard output if the value of modelYear falls within those two ranges.

  Write a program that generates all the factors of a number

Write a program that generates all the factors of a number entered by the user. For instance, the number 12 has the factors 2 * 2 * 3.

  Create program to enter number of packages bought

Create a program which asks user to enter number of packages bought . The program must then display amount of discount (if any) and total amount of purchase after the discount.

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