a) Write a function to simulate coin tossing, the function will use rand function that gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail. b) Write a complete program in C to take a number (N) from the user and toss the coin N times using the function defined in part a), and count the number of Heads and number of Tails. Finally, print a histogram using ** for the number of Heads and Tails. For example, if the number of Heads is 5 and number of Tails is 10, the
Q: Question 2: Write a program that defines a function, RoundToThousands(number), to round a number x…
A: Step 1:- Program Approach:- 1.Declare the user-defined function that function takes one parameter.…
Q: 6. Write a function which takes only your full name as input and finds the total number of vowels in…
A: Please find the program to display count and vowels in the given input name:
Q: Q2: Write C++ program to read student mark as integer type and prints out its corresponding grade…
A: #include<iostream> using namespace std; //grade function void grade(int m){ if(m>=90…
Q: QUESTION 22 Write ONLY the function to do the following: Input a number selected by the user That…
A: Answer: Here not mentioned any programming language so we will do code in C++ Programming language…
Q: b) Write appropriate C++ statements for the following tasks, to get the input from users, find the…
A: Below I have provided a C++ program for the given question. Also, I have attached a screenshot of…
Q: Write the function int isEven (int x); that returns 1 if x is an even number; otherwise, it returns…
A: please check the step 2 for required c++ code and step 3 for output.
Q: Write a function “func(n)” that returns the number of values generated until all values are obtained…
A: To write a function that returns the number of values generated using Harmonic.
Q: 4-Write the definition of function with two parameters (start and end) of type int. The function…
A: 4. // Function Definition void PrintNaturalNumbers(int start,int end){ int temp = start;…
Q: 13- Write a function that takes a positive integer "n" as the function parameter and returns True if…
A: Take a number from user declare a temp variable that is set to False check if the number is greater…
Q: 3. Write and test a function hydroxide that returns a 1 for true if its string argument ends in the…
A: As per our guidelines we are supposed to answer only one question. Kindly repost the remaining…
Q: Given two overloaded functions below. int f(int &a, int b) { int c = a + b; a = a+1; b = b+1; return…
A: Consider the first function: int f(int &a,int b) { int c=a+b; a=a+1; b=b+1; return c; }
Q: b) Write a complete C- Program for Student Grade Computation. Program will use two user defined…
A: Step 1:- Program Approach:- 1.Include header file 2.Create two user-defined function whose name…
Q: Q3) a) Write a function to simulate coin tossing, the function will use rand function that gives an…
A: #include <stdio.h>#include <stdlib.h> int randomnu() //part a.{ return rand() % 2;…
Q: Consider proper alignment and indentation of statements when answering the following questions. a)…
A: Here in the first part of the given scenario to return the particular function the return keyword is…
Q: Display the first N magic numbers, where N is a positive number that the user provides as input.…
A: Program code: #include <iostream>using namespace std; bool isMagic(int value);int main(){…
Q: Q5: Write a C++ program to read a number that represents the number of days, then send this number…
A: Required: I need the answer quickly
Q: What statement about the print() function is true? A. print() has a variable number of parameters.…
A: What statement about the print() function is true? A. print() has a variable number of parameters.…
Q: #13. Let the function fun be defined as int fun (int k) *k + 4; return 3 (*k) - 1; Suppose fun is…
A: a. if the operands in the expressions are evaluated left to the right? given i = 10 then, sum1 =…
Q: 9. Do Programming Exercise 3 from Chapter 5 using a function grade(score) that returns the letter…
A: Functions in python: Functions provide a way to break problems or processes down into smaller and…
Q: Q2/Write a program that reads from the user the value of x and apply the function below:
A: Consider the given functions : Note: Since the programming language is not mentioned i used "C"…
Q: 17. Write a sub-function “conversion()" based on the program below to convert the time to unit…
A: code snippet:
Q: Write a function that displays all the numbers between two integers in n lines, that are divisible…
A: Program: A program is used to interact with computer systems and solve complex problems. The main…
Q: 10. Do Programming Exercise 4 from Chapter 5 using a function acronym (phrase) that returns an…
A: Please refer below for your reference: I have took a string for testing purpose rest all conditions…
Q: Create a function sumofAllOdd(s,e) that will return the sum of all odd numbers in a range of…
A: Create a function sumofAllOdd(s,e) where s is start of the range and e is the end of range Using for…
Q: 1. Write a function is divisible that takes two numbers and Nas inputa, and that returns True (the…
A: Python Program: # Takes two number m and n as user inputm = int(input("Enter the value of m: "))n =…
Q: Write a function days_in_month() that returns the number of days in a month. The function has the…
A: PROGRAM CODE: #include <stdio.h> // include…
Q: C++ Coding Question, Fill the void function *n1, int *n2, int *n3) void passReference(int ( // Write…
A: Coded using C++.
Q: Q3: ) A: Write a program to find the value of (C) from the following function C=exp- where -Ea, xb,…
A: First, we will define the two vectors, a and b. Then using for loop, we find the numerator and…
Q: 5.b. Does a function return single or multiple value? When and how a function will return single or…
A: A single value can be returned of the provided return type in the function signature without any…
Q: Q9/Write program. in c++ a that inputs three-digit integer, separates the integer into its…
A: The program reads a 3 digit integer value from the user using a variable n then separates each…
Q: n C++ Write the definition of a value-returning function that accepts two integer parameters and…
A: Given: Two integer parameters as argument to a function. Requirement: Return a float value to return…
Q: Q:1 a) Can a predefined function be recursively called by the programmer? Elaborate. b) Write a…
A: a) A predefined function cannot be recursively called by the programmer as its definition is…
Q: Write the definition of a function that takes as input the three numbers. The function returns true…
A: Since, programming language is not mentioned in the question, we will answer this question in C++…
Q: Write C++ funtion GCD(int a, int b) having single line of code only in the function. Don't answer…
A: Given: Write C++ funtion GCD(int a, int b) having single line of code only in the function. Don't…
Q: n this small funtion, identify and define each part of the function int addition (int a, int b) {…
A: Program: A program is a set of lines code that contains instructions to perform a specific task.In…
Q: Program 3: Write a value-returning function isVowel that returns the value true if a given character…
A: Aim: Write a value returning function isVowel to find if a character is a vowel or not. The program…
Q: Write a program in c++ for entering minutes and converting them into hours and minutes
A: START Step 1-> declare function to convert hours into minutes and seconds void convert(int…
Q: 9. Write a function that receives marks received by a student in 7 subjects and returns the avera…
A: Program Approach: Include necessary header files to get the standard I/O. Define a function to…
Q: Please fix of couple things in the code below. A couple of things. The input value is the waist…
A: Algorithm: Start Read waist size if waistSize is between 26 and 28 print "pant size is XXS" else if…
Q: Please solve the problem in R-STUDIO, IN R LANGUAGE. THANK YOU Q. Write a function which will take…
A: Write a function which will take 1 argument, the number of days. a. Your first task is to take the…
Q: 2. Write a function named "MyInfo ()". Now pass three parameters to your function i.e. your name,…
A: Step 1:- Program Approach:- 1.Declare the function whose name is MyInfo and this function takes 3…
Q: Write a function receive 3 numbers and return the summation of them. *
A:
Q: Rewrite the following function using just a single statement (which must be a return statement).…
A: Given: def thing(i, j): if i> 10: if j < 5 or i> 20: return False…
Q: Q 5: Returning -value Function (return.py) Give an example from your own, of a program that use a…
A: Actually, function is a group of statements.
Q: 2: Modify your tip calculator program so that it uses a function that take the bill amount, tax and…
A: First of all accept bill amount. Accept tax percentage from the user. Accept tip amount to be paid.…
Q: Fill-in-the-Blank When only a copy of an argument is passed to a function, it is said to be passed…
A: EXPLANATION Parameters are defined during function declaration. These variables are used to take…
Q: Please use C++. Write the following function declarations as they would appear on single lines above…
A: Function declarations in C++ a. bool doTheLogic(bool a) b. bool doTheLogic(bool a, bool b) c. bool…
Q: 1. Write a program in python that contains a main function and a custom, void function named…
A: Program AlgorithmIn the main(), generate the two random numbers and call the function show_larger()…
Q: Write a program that uses input to prompt a user for their name and then welcomes them. Enter your…
A: We write a function named greet by passing single argument str of type string, displaying welcome…
a) Write a function to simulate coin tossing, the function will use rand function that
gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail.
b) Write a complete program in C to take a number (N) from the user and toss the coin
N times using the function defined in part a), and count the number of Heads and
number of Tails. Finally, print a histogram using ‘*’ for the number of Heads and
Tails. For example, if the number of Heads is 5 and number of Tails is 10, the
following histogram will be printed: (Hint: Use for loops for repetition and if/else
for selection of Head or Tail).
Output:
Head: 10 **********
Tail: 5 *****
Step by step
Solved in 2 steps with 2 images
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.Q3) a) Write a function to simulate coin tossing, the function will use rand function that gives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail. b) Write a complete program in C to take a number (N) from the user and toss the coin N times using the function defined in part a), and count the number of Heads and number of Tails. Finally, print a histogram using * for the number of Heads and Tails. For example, if the number of Heads is 5 and number of Tails is 10, the C C language following histogram will be printed: (Hint: Use for loops for repetition and iflelse for selection of Head or Tail). Output: Head: 10 * ********* Tail: 5 *****Q3)a) Write a function to simulate coin tossing, the function will use rand function thatgives an output 0 or 1. Then function will return 0 as Head and return 1 as Tail.b) Write a complete program in C to take a number (N) from the user and toss the coinN times using the function defined in part a), and count the number of Heads andnumber of Tails. Finally, print a histogram using ‘*’ for the number of Heads andTails. For example, if the number of Heads is 5 and number of Tails is 10, the following histogram will be printed: (Hint: Use for loops for repetition and if/elsefor selection of Head or Tail).
- Q:1 a) Can a predefined function be recursively called by the programmer? Elaborate. b) Write a program in C to take input for an integer.If the given integer is prime then display the product of its digits otherwise check whether it is even or odd.Use minimum three functions including main function.in C++ program please: part a) According to Wikipedia: “The International Collegiate Programming Contest, known as the ICPC, is an annual multi-tiered competitive programming competition among the universities of the world.” Moreover, the participants of the contest should be no older than 24. Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters. int calculateAge(int current_year, int birth_year) { part b) The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility. Note: solution should use calculateAge ! int main() { int studentsAge[10]; #your answer for (int i = 0; i < 10; i++) { cin >> studentsAge[i]; # your answer Your program…in C++ program please: part a) According to Wikipedia: “The International Collegiate Programming Contest, known as the ICPC, is an annual multi-tiered competitive programming competition among the universities of the world.” Moreover, the participants of the contest should be no older than 24. Complete the following function which takes as input two parameters: the current year and the birth year of a student. The function should return the age of the person given the parameters. int calculateAge(int current_year, int birth_year) { part b) The teacher wants to determine if a group of students is eligible for this competition. Complete the following piece of code considering that the age of these students are stored in the studentsAge array and use the calculateAge function to determine the eligibility. Note: solution should use calculateAge ! int main() { int studentsAge[10]; #your answer for (int i = 0; i < 10; i++) { cin >> studentsAge[i]; # your answer Your program…
- 1. Write a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, then the pattern generated is:********************Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the above pattern. 2. A palindrome is a string that reads the same both forward and backward. For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameter.Excercise # 2 Write a function def isLeapYear(year) that tests whether a year is a leap year, that is, a year with 366 days. Note that a year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400. • Following are sample runs: enter a year number: 1600 1600 is a leap year enter a year number: 2020 2020 is a leap year enter a year number: 1000 1000 is not a leap year Slide Type # YOUR CODE HERE # Hint: if (year%4=30 and year %100 !=0) or year%400 == e: def isleapYear(year): # Write the code of the function here def main(): year = int(input("enter a year number: ")) main ()Write and test the “digit” function:Function Prototype: int digit(int n,int k)This function returns the kth digit of the positive integer n. For example, if n is the integer 29,415, then the call digit(n,0) would return the digit 2, and the call digit(n,2) would return the digit 4.
- ***in python only*** use turtle function Define the concentricCircles function such that: It draws a series of concentric circles, where the first parameter specifies the radius of the outermost circle, and the second parameter specifies the number of circles to draw. The third and fourth parameters specify an outer color and an other color, respectively. The outer color is used for the largest (i.e., outermost) circle, and then every other circle out to the edge alternates between that color and the 'other' color. The difference between the radii of subsequent circles is always the same, and this difference is also equal to the radius of the smallest circle. Put another way: the distance between the inside and outside of each ring is the same. Define concentricCircles with 4 parameters Use def to define concentricCircles with 4 parameters Use any kind of loop Within the definition of concentricCircles with 4 parameters, use any kind of loop in at least one place. Call…26 LAB: Rolling for a pair Given two GVDie objects that represent 2 six-sided dice and an integer that represents a desired value as parameters, complete the function rolling for pair(). The function rolling for pair() rolls the dice until a pair with the desired value is rolled and then returns the number of rolls thrown to achieve the result. Assume the desired value received from input is within the appropriate range, 1-6. Note: For testing purposes, the GVDie objects are created in the main() function using a pseudo-random number generator with a fixed seed value. The program uses a seed value of 15 during development, but when submitted, a different seed value will be used for each test case Ex If the GVDie objects are created with a seed value of 15 and the input of the program is: 3 the output is: It took 13 rolls to get a pair of 3's. 375860 2438106.qx3zay?Assignment Write a program to calculate n! for a given number n and perform the simple calculator operations. The valid operations of the calculator are: + add - sub * mul I div The program must contain a function fact with one input parameter that returns the factorial of a number, a function add that performs the addition of two numbers, a function sub that performs the subtraction of two numbers, a function mul that performs the multiplication of two numbers, a function div that performs the division of two numbers. The program must also check for bad input data. Make sure when you pass parameters you pass the addresses (not the value). • All function return type must be of type void. • Take inputs in main function. • Pass the addresses of the operands and the address of the result to each function. Output must be displayed as follows: 1: Addition 2: Subtraction 3: Multiplication 4: Division 5: Factorial 6: Quit Enter the choice => 1 Enter two numbers => 2, 3 Sum => 5