I wrote a code for which
if 23E+20 is the input then output should be 230000000(20 zeros)
if 4.456E-14 is the input then 4.456000(14 zeros) should be the output
But its not working properly. Please let me know where I did error. Thank You.
C#
using System;
class test
{
public static void Main()
{
Console.WriteLine("Enter double");
String ext =Console.ReadLine();
if(ext.IndexOf("E")!=-1)
{
int i=ext.IndexOf("E");
ext = ext.Substring(0, i);
for (int j = 0; j int.Parse(ext.Substring(i + 1, ext.Length - (i + 1))); j++)
ext = ext + "0";
Console.WriteLine(ext);
}
}
Kirtan PatelRank #292 · 8.6K reputationPosted Feb 16, 2010, 10:54 PM EST
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Number :");
string Input = Console.ReadLine();
string[] SplitString;
string FinalOutput = "";
if (Input.Contains('+') == true)
{
SplitString = Input.Split('+');
Regex rex = new Regex("[0-9.]*");
Match m = rex.Match(SplitString[0]);
FinalOutput = m.Value.ToString();
int NumberofZero = int.Parse(SplitString[1]);
for (int i = 0; i < NumberofZero; i++)
{
FinalOutput += "0";
}
//Show Output
Console.WriteLine("\n ************ Output ***************");
Console.WriteLine(FinalOutput);
}
else if (Input.Contains('-') == true)
{
SplitString = Input.Split('-');
Regex rex = new Regex("[0-9.]*");
Match m = rex.Match(SplitString[0]);
FinalOutput = m.Value.ToString();
int NumberofZero = int.Parse(SplitString[1]);
for (int i = 0; i < NumberofZero; i++)
{
FinalOutput += "0";
}
//Show Output
Console.WriteLine("\n ************ Output ***************");
Console.WriteLine(FinalOutput);
}
Console.ReadLine();
}
}
}
Rujuta133 reputationPosted Feb 16, 2010, 10:55 PM EST
using System; class test { public static void Main() { Console.WriteLine("Enter double"); String ext =Console.ReadLine(); if(ext.IndexOf("E")!=-1) { int i=ext.IndexOf("E"); ext = ext.Substring(0, i); for (int j = 0; j int.Parse(ext.Substring(i + 1, ext.Length - (i + 1))); j++) ext = ext + "0"; Console.WriteLine(ext); } } ext=ext.Substring(0,i) will overwrite the actual string. That is, ext is now the chars coming before the letter "E" and not the original string. Take another string instance to store both the substrings.Rujuta133 reputationPosted Feb 16, 2010, 10:56 PM EST
using System; class test { public static void Main() { Console.WriteLine("Enter double"); String ext =Console.ReadLine(); if(ext.IndexOf("E")!=-1) { int i=ext.IndexOf("E"); ext = ext.Substring(0, i); for (int j = 0; j int.Parse(ext.Substring(i + 1, ext.Length - (i + 1))); j++) ext = ext + "0"; Console.WriteLine(ext); } } ext=ext.Substring(0,i) will overwrite the actual string. That is, ext is now the chars coming before the letter "E" and not the original string. Take another string instance to store both the substrings.