Student Of Fortune

Make Anagram with C #. net

Share on :
Anagram is one type of word game, where the letters in the word initial randomized to usual form another word or a sentence. Anagram frequently used as a code. Games that use anagrams include Scrabble and Boggle. In both these games, players try to form words from letters which are provided.

Logic Program
1. Do Anagramisasi, is the process of forming an anagram for the letters to the right of the first letter. If the sentence entered by the user has n letters, of course we need to do as much as n-1 anagramisasi fruit remaining letters. In this program, we call the method doAnagram () as a method of cultivating his anagrams.

2. Perform the rotation of letters, for a number of n letters. This rotation means to shift all the letters one position to the left, except the leftmost letter.

3. Perform the above steps as many as the number of letters in the word / phrase that entered by users 
(n times).
 
the syntax :
[source code language = "csharp"]  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationAnagram
{
class Program
{
static int size;
static int count;
static char [] arrChar = new char [100];

static void Main (string [] args)
{
/ / Get language from the user.
Console.Write ("Enter sentence:");
String input = Console.ReadLine ();
Console.Write ("\ n \ n");
/ / Get the size of the sentence.
size = input.Length;
count = 0;
for (int j = 0; j <size; j + +)
/ / Put the sentence in the array.
arrChar [j] = input [j];
doAnagram (size); / / Prepare an anagram.
Console.ReadLine ();
}
/ / method to do anagramisasi.
private static void doAnagram (int newSize)
{
/ / If the size is too small
/ / (basic recursive).
if (newSize == 1)
return;
/ / For each position.
for (int j = 0; j <newSize; j + +)
{
/ / Time anagrams.
doAnagram (newSize - 1);
/ / If done, show!
if (newSize == 2)
displayWord ();
/ / Perform the rotation of the sentence.
rotate (newSize);
}
}

/ / Perform the rotation.
private static void rotate (int newSize)
{
int j;
int position = size - newSize;
/ / Save the first letter.
char temp = arrChar [position];
for (j = position + 1; j <size; j + +)
/ / Scroll the other letters to the left.
arrChar [j - 1] = arrChar [j];
/ / Put the first letter to the right.
arrChar [j - 1] = temp;
}
/ / Displays the Console screen.
private static void displayWord ()
{
if (count <99)
Console.Write ("");
if (count <9)
Console.Write ("");
Console.Write (+ + count + "");
for (int j = 0; j <size; j + +)
Console.Write (arrChar [j]);
Console.Write ("");
if (count% 6 == 0)
Console.Write ("");
}
}
}
 

0 comments on Make Anagram with C #. net :

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank