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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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