1. Given a integer N, print the decimal form of 1/2n. Example: N=1, print 0.5 N=2, print 0.25 Adding leading/unsignificant zeroes will lead to wrong answer. Example, printing 0.50 instead of 0.5 in above case will lead to wrong answer. So correct output of 100 will be 0.0000000000000000000000000000007888609052210118054117285652827862296732064351090230047702789306640625 Output for 50 : 0.00000000000000088817841970012523233890533447265625 Output for 200 : 0.0000000000000000000000000000000000000000000000000000000000006223015277861141016250579646224554209682103144689201443821087459887188032139105827696600570131548979236366311772064357280932527780316951302892084253444264507759697835354018025100231170654296875
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Divideby2 { class Program { static void Main(string[] args) { int t = Convert.ToInt32(Console.ReadLine()); int[] a = new int[t]; for (int i = 0; i < t; i++) { a[i] =Convert.ToInt32(Console.ReadLine()); } for (int j = 0; j < t; j++) { double n = a[j]; string res = (1 / (Convert.ToDouble(Math.Pow(2, n)))).ToString(); decimal d = decimal.Parse(res, System.Globalization.NumberStyles.Any); Console.WriteLine(d); } Console.Read(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)