using System namespace ConsoleApplication2 class Program static void Main

Using system namespace consoleapplication2 class

This preview shows page 17 - 23 out of 23 pages.

using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; int i = 0; Console .WriteLine ( "Enter number :" ) ; x= Convert .ToInt32( Console .ReadLine()); while (i < x); { i = i + 1 ; Console .WriteLine ( "Hellow World " ); if (i == 4) { i = 8; } } Console .ReadKey (); } } } Do looping : 7 using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; int i = 0; Console .Write( "Enter number :" ); x = Convert .ToInt32( Console .ReadLine()); do { Console .WriteLine( "Hellow World " ); i = i + 1 ; } while (i < x);
Image of page 17
Console .ReadKey(); While looping : 7 using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; int i = 0; Console .Write( "Enter number :" ); x = Convert .ToInt32( Console .ReadLine()); while (i < x) { Console .WriteLine( "Hellow World " ); i = i + 1; } Console .ReadKey(); } } }
Image of page 18
For looping: 5 using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; int i = 0; Console .Write( "Enter number :" ); x = Convert .ToInt32( Console .ReadLine()); for ( int I = 0; i < 5; i = i + 1) { Console .WriteLine( "Hellow World " ); } if ( i== 4) { i = 8 ; } Console .ReadKey(); } } }
Image of page 19
5.Sample input: Enter 1st character: p Sample output: P P P P P P P P P P P P P Ans wer namespace ConsoleApplication2 { class Program { static void Main( string [] args) { char x; Console .Write( "Entre any character:" ); x = Convert .ToChar( Console .ReadLine()); for ( int i=0; i<5; i=i+1) { if (i==2) { Console .WriteLine(x+ " " +x+ " " +x+ " " +x+ " " +x); } else if (i==1||i==3) { Console .WriteLine( " " + " " +x+ " " +x+ " " +x); } else { Console .WriteLine( " " + " " + " " + " " +x); } } Console .ReadKey(); } } }
Image of page 20
Sample Input: Enter any Character: A Sample output: A A A A A using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { char x; Console .Write( "Enter any character :" ); x = Convert .ToChar( Console .ReadLine()); for ( int i = 0 ; i < 3 ; i = i+1) if (i==1) { Console .WriteLine( x + " " +x+ " " + " " +x); } else { Console .WriteLine( " " + " " + " " + x ) ; } Console .ReadKey(); } }
Image of page 21
} Input 10 and output showing 6 times: using System; namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; Console .Write( "Enter number" ); x= Convert .ToInt32( Console .ReadLine ()); for ( int i = 0; i < 10; i = i + 1) { Console .WriteLine( "hello world" ); if (i == 4) { i = 8; } } Console .ReadKey(); } } }
Image of page 22
5.Sample input: Enter 5 digit number: 12345 Sample output: Reverse is:54321 Answer namespace ConsoleApplication2 { class Program { static void Main( string [] args) { int x; int y; Console .Write( "Entre 5 digit number:" ); x = Convert .ToInt32( Console .ReadLine()); y = (y = 0); while (x > 0) { int rem = x % 10; y = (y * 10) + rem; x = x / 10; } Console .WriteLine( "The reverse is={0}" ,y); Console .ReadKey(); } } }
Image of page 23

You've reached the end of your free preview.

Want to read all 23 pages?

  • Spring '16
  • MD.Kamruzzaman

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes