Examples
if the input integer is | return |
1234 | 4321 |
12005 | 50021 |
1 | 1 |
1000 | 1 |
0 | 0 |
-12345 | -54321 |
by java
public class ReverseIntegers { public int f(int n) { int sign = 1; if (n < 0) { sign = -1; n = -1 * n; } int rev = 0; while (n > 0) { rev *= 10; rev += n % 10; n /= 10; } return sign * rev; } public static void main(String[] args) { System.out.println(new ReverseIntegers().f(1234)); System.out.println(new ReverseIntegers().f(12005)); System.out.println(new ReverseIntegers().f(1)); System.out.println(new ReverseIntegers().f(1000)); System.out.println(new ReverseIntegers().f(0)); System.out.println(new ReverseIntegers().f(-12345)); } }
Write a function to reverse an integer using numeric operators and without using any arrays or...
Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...
use java and write in text a. Rewrite the following code segment using if statements. Assume that grade has been declared as of type char. char grade= 'B';; switch (grade) { case 'A': System.out.println("Excellent"); break case 'B': System.out.println("Good"); default: System.out.println("you can do better”); } - b. write Java code that inputs an integer and prints each of its digit followed by ** e.gif the integer is 1234 then it should print 1**2**3**4 e.g. if the integer is 85 then it...
Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...
c++ write a boolean function that accepts two integer arrays of size 10 as input parameters, the function should return true if there are any similar values between the two arrays and shall return false if not, if there are similar values, print out on screen
Needs to be done in C, The function shown can be called to reverse the char. 7.5 Bit Encryption 7.5.1 Problem Given a single character, apply a simple bitwise encryption algorithm and return the cipher character. 7.5.2 Preconditions You must provide a series of functions which meet the requirements in the table below. You you may include other functions as long as the requested functions execute correctly. Do not include a main function in your source or header files. You...
use C++ Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse any given word. 2. Write a program that will: Ask the user to enter a word. Save the entry as word_entered. Call word_rev on the entry Display the reversed entry (word_entered) 3. Write a function named prime() that determine whether or not a given number n (greater than one) is prime. The algorithm: If n is even then n is not a prime number...
Write a function in HASKELL to reverse a string (or list) without using the built-in reverse function. Example: Hello as olleh or [1,3,4,5] as [5,4,3,1].
Java Program: Write an algorithm (steps) using pseudocode (no java code required) explaining steps for a method which will reverse an integer array (Integer[]) without using any other data structure. The method should return the reversed integer array. E.g. If input array Integer[] integers = [1,2,3,4,5,6] should return [6,5,4,3,2,1]
Using the programming language Java or C++, Write a function that takes an integer as input. Return true if this integer is a palindrome integer; false otherwise;
9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named...