Write a C program requesting the user to input two integer numbers and then requesting the user to either add, subtract, or multiply the two numbers (choose 0 to add, 1 to subtract, or 2 to multiply. Declares three separate functions for these choices to come after main(). Program needs to use a pointer to these three functions to perform the requested action. Must print to output.
#include <stdio.h>
int add(int,int);
int sub(int,int);
int mul(int,int);
int main()
{
int n1,n2,op;
printf("Enter 2 numbers : ");
//reading 2 numbers from user
scanf("%d%d",&n1,&n2);
printf("choose 0 to add, 1 to subtract, or 2 to multiply");
scanf("%d",&op);
//declaring function pointer
int (*fp)(int, int);
//assinging function name based on user input
if(op==0)
fp=add;
if(op==1)
fp=sub;
if(op==2)
fp=mul;
printf("Result is : %d",fp(n1,n2));
return 0;
}
int add(int n1,int n2){
return n1+n2;
}
int sub(int n1,int n2){
return n1-n2;
}
int mul(int n1,int n2){
return n1*n2;
}
Write a C program requesting the user to input two integer numbers and then requesting the...
Write a C program as follows: Single source code file Requests the user to input two integer numbers Requests the user to make a choice between 0 (add), 1 (subtract), or 2 (multiply) Declares three separate functions Uses a pointer to these three functions to perform the requested action Outputs the result to the screen Submit your program source code file to this assignment. Sample Output Enter first integer number: 15 Enter second integer number: 10 Enter Choice: 0 for...
Write a java program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times asking for an integer...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to input 10 int numbers from the user...
Write a program that asks the user to input a 4-digit integer and then prints the integer in reverse. Your program needs to implement a function reverse that will take in as input the 4-digit number and print it out in reverse. Your code will consist of two files: main.s and reverse.s. Main.s will ask for the user input number and call the function reverse. For ARM/Data Structure needs to be able to run on Pi Reverse.s will take in...
Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...
1- Write a C program to add and subtract any two given integer numbers using pointers. 2- Write a C program to find the factorial using a function and pointers. 3- Write a C program to find the square of an Integer number using a function and pointers. 4- Write a C program to find the area and perimeter of a rectangle using a function and pointers. 5- Write a C program to find the larger of two integers numbers using...
Write three functions, float getNum(), float add(float, float), void outSum(float); that asks user for two numbers, finds the sum of two numbers, and displays the sum repeatedly in a main program until the user enter "0" for either one of the numbers.
Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions
Write three functions, float getNum(), float add(float, float), void outSum(float); that asks user for two numbers, finds the sum of two numbers, and displays the sum repeatedly in a main program until the user enter "0" for either one of the numbers. (In C++)
Write program in C. Please ask the user to determine how many numbers to enter, and then find and display the largest one with two digits. Please call the following two functions in your main functions. void input_numbers(float *data, int num); void find_largest(float *data, int num); Note: In this assignment, please save the entered numbers using pointer, pass the pointer as the arguments. Depending upon the number of elements, the required size is allocated which prevents the wastage of memory....