Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Write a Python program that takes a number and prints how many digits are in that number.


[Consider the input number to be an INTEGER.]



[You are not allowed to use len() function]



Example: If the user gives 9876, your program should print 4.

Write a Python code that will read 5 numbers from the user. Your program should print the first number, the sum of the first 2 numbers, the sum of the first 3 numbers, and so on up to the sum of 5 numbers.

==========================================================

Sample Input 1:

1

2

3

4

5

Sample Output 1:

1

3

6

10

15


double sin = MathAssignment.sine(1.047197551);

After the execution of the above method call, the value stored in variable sin will be (approximately)

0.866025404, as the sine of 1.047197551 radians is approximately 0.866025404. The

sine of an angle x, denoted sin x, can be calculated using the following algorithm:

• If x < -π, repeatedly add 2π to x until -π ≤ x ≤ π. Conversely, if x > π, repeatedly subtract 2π

from x until -π ≤ x ≤ π. You MUST use 3.141592653589793 as a value


Write a Python program that asks the user for a quantity, then takes that many numbers as input and prints the maximum, minimum and average of those numbers.


[Please note that you CANNOT use max, min built-in functions]


[Also, you DO NOT need to use lists for this task]


==========================================================


Example: If the user enters 5 as an input for quantity and the enters the 5 numbers, 10, 4, -1, -100, and 1.

The output of your program should be: “Maximum 10”, “Minimum -100”, “Average is -17.2” as shown below.


Input:

5

10

4

-1

-100

1


Output:

Maximum 10

Minimum -100

Average is -17.2


Mark the following statements as true or false.



a. All members of a struct must be of different types.



b. A function cannot return a value of type struct.



c. A member of a struct can be another struct.



d. The only allowable operations on a struct are assignment and member selection.



e. An array can be a member of a struct.



f. In C++, some aggregate operations are allowed on a struct.



g. Because a struct has a finite number of components, relational operations are



allowed on a struct.




Compare and contrast Programmed Input-Output Communication technique and Interrupt-driven Input-Output Communication technique.



# Various Icecream flavors
menu_item1 = "Chocolate"
menu_item2 = "Vanilla"
menu_item3 = "Strawberry"

order = input("\nWhich flavors would you like on your icecream today?\n\n" +
              "\n".join([menu_item1, menu_item2, menu_item3]) + "\n\n")

# Convert input to list of flavors.
order = order.lower().split()
plural = "s" if len(order) > 1 else " "
union = " and " if len(order) > 1 else " "
print("\nYou have selected " + ", " .join(order[:-1]) + union + order[-1] + " flavor" + plural)


Question: How do I fix the Extra space for 1 flavor of choice and duplicated words and comma's for 2 or more flavors of choice?


My Output: "You have selected Chocolate flavor"

My Output: "You have selected Chocolate, and and Vanilla flavors"

My Output: "You have selected Chocolate, , Vanilla, and and Strawberry flavors"


Consider the following statements:


int num1, num2, num3;


double length, width, height;


double volume;


num1 = 6;


num2 = 7;


num3 = 4;


length = 6.2;


width = 2.3;


height = 3.4 and the function prototype: double box(double, double, double);


Which of the following statements are valid or invalid?


a. volume = box(length, width, height);


b. volume = box(length, 3.8, height);


c. cout << box(num1, num3, num2) << endl;


d. cout << box(length, width, 7.0) << endl;


e. volume = box(length, num1, height);


f. cout << box(6.2, , height) << endl;


g. volume = box(length + width, height);


h. volume = box(num1, num2 + num3);



Searching an element in a sorted array


standard input/output: 2s/128000 kB


Given a sorted array arr[] of N integers and a number K is given. The task is to check if the element K is present in the array or not.


Note: Use binary search to solve the problem

Input

The first line of input contains a number of test cases T. For each test case, first line of input contains a number of elements in the array, and the number K separated by space. The next line contains N elements.


Constraints:

1 <= T <= 10

1 <= N <= 100000

1 <= K <= 1000000000

1 <= arr[i] <= 1000000000


Sum of N over all test cases doesn't exceed 106

Output

For each testcase, if the element is present in the array print "1" (without quotes), else print "-1" (without quotes).



GCD of LCM! (Contest)


standard input/output: 2s/128000 kB


You are given an array A consisting of N number and an empty set S. For each pair of numbers A[i] and A[j] in the array (i < j), you need to find their LCM and insert the LCM into the set S.


You need to report the GCD of the elements in set S.

Input

The first line of the input contains an integer N.

The second line of the input contains N space separated integers A[1], A[2],. , A[N].


Constraints

2 <= N <= 100000

1 <= A[i] <= 200000

Output

Output a single integer, the GCD of LCM set S.



LATEST TUTORIALS
APPROVED BY CLIENTS