Business Logic for the given condition.

Posted by Gokul under C# on 6/23/2011 | Points: 10 | Views : 949 | Status : [Member] | Replies : 6
Dear Friends,
I want the output to be like shown below:

5 4 3 2 1
1 2 3 4
3 2 1
1 2
1



Input="welcome"
Output: w $ e$ l $ c$ o $ m $ e

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Jpchoudhari on: 6/23/2011 [Member] Starter | Points: 25

Up
0
Down
static void Main(string[] args)
{
Console.WriteLine("Enter no ");
int cnt = int.Parse(Console.ReadLine());
int iCnt = cnt;
int iDisplay = cnt;
for (int i = 1; i <= cnt; i++)
{
if (i % 2 != 0)
iDisplay = iCnt;
else
iDisplay = 1;
for (int j = iCnt; j > 0; j--)
{
if (i % 2 != 0)
{
Console.Write(iDisplay + " ");
iDisplay--;
}
else
{
Console.Write(iDisplay + " ");
iDisplay++;
}
}
iCnt--;
Console.WriteLine();
}
Console.ReadLine();
}




static void Main(string[] args)
{
Console.WriteLine("Enter string : ");
string strLabel= Console.ReadLine();
for (int i = 0; i < strLabel.Length; i++)
{
Console.Write(strLabel[i]);
if (i < strLabel.Length-1)
Console.Write(" $ ");
}
Console.ReadLine();
}

Thanks and Regards,
Jaydeep Choudhari

Kind Regards,
Jay

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
second code is not giving output as per requirement
actual o/p w $ e $ ...
but your code gives welcome $ welcome $ ..

Thanks&Regards
LakshmiNarayana Nalluri.

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
and modify your code as

Console.Write(strLabel(i));


Thanks&Regards
LakshmiNarayana Nalluri.

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
int number = 5;

while (number > 0)
{
PrintToOne(number);
Console.WriteLine();
number--;
}
public static void PrintToOne(int num)
{
for (int i = num; i > 0; i--)
{
Console.Write(i+" ");
}
}



string str = "Hello";
StringBuilder sb=new StringBuilder();
for (int i = 0; i < str.ToCharArray().Length; i++)
{
sb.Append((i > 0 ? "$" : "") + str.ToCharArray()[i]);
}
Console.WriteLine(sb.ToString());


Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down

@Lakn2 : ya that was my mistake.. i forgot to add index position.

@Ndebata: have u chekd ur outputs???

Thanks and Regards
Jaydeep Choudhari

Kind Regards,
Jay

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
@Jpchoudhari

This is the problem with the editor control not showing the index [i] after str.ToCharArray() inside the loop, instead it made rest of the text to italic.

Thanks,
Debata

Gokul, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response