Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Four Digit Number
//Write a Boolean expression that checks for given integer if it can be divided (without remainder) by 7 and 5 in the same time. Examples: using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int number = 9876; // gets every digit and creates an array with int elements int[] num = new int[4]; num = ReverseOrder(number); //creates an array with all digits in a string format string[] stringNum = new string[4]; stringNum = StringArray(num); //Now that we have converted the digits to string, you can easily use the + operator to create the new numbers and convert them to integer //calculates the sum of all digits int sumOfDigits = (num[0] + num[1] + num[2] + num[3]); Console.WriteLine("The sum of digits is: {0}", sumOfDigits); //Creates the reverse number string reverseNumber = stringNum[0] + stringNum[1] + stringNum[2] + stringNum[3]; Console.WriteLine("The reverse number is: {0}", reverseNumber); //Exchange 1st and last number string exchange1st = (stringNum[0] + stringNum[3] + stringNum[2] + stringNum[1]); Console.WriteLine("Number after exchanging first and last digit: {0}", exchange1st); // Exchange 2nd and third number string exchange2nd = (stringNum[3] + stringNum[1] + stringNum[2] + stringNum[0]); Console.WriteLine("Number after exchanging second and third digit: {0}", exchange2nd); } public static int[] ReverseOrder(int number) { int[] num = new int[4]; num[0] = (number %10); number = (number/10); num[1] = (number %10); number = (number / 10); num[2] = (number %10); number = (number / 10); num[3] = (number %10); //Shows all digits /*foreach (int numbers in num) { Console.WriteLine(numbers); }*/ return num; } public static string[] StringArray(int[] num) { string[] stringNum = new string[4]; for (int i = 0; i < num.Length; i++) { stringNum[i] = num[i].ToString(); } return stringNum; } } }
run
|
edit
|
history
|
help
0
6.2 Parallelism: locks
walle
THRWSC SDXS
Pascal Tringle
custom Generic Que Implementation
barcos
Prim`s Algorithm
4
Diagonal Difference
Working (C# thing)