Pages

Tampilkan postingan dengan label characters. Tampilkan semua postingan
Tampilkan postingan dengan label characters. Tampilkan semua postingan

Senin, 09 Mei 2016

C Simple Loop Program example to print characters

Simple Loop Problem to Print A B D H P

Problem Statement:
Write a program using for loop which prints the following output. (You have to find a pattern to print alphabetics in this order)
A B D H P

Solution:

static void Main(string[] args)
{
int i,j,ch=0,n;
Console.Write("A ");
for (i = 1; i <= 4; i++)
{
n = 1;
for (j = 1; j <= i; j++)
{
n = n * 2;
ch = 64 + n;
}
Console.Write((char)ch + " ");
}

Console.ReadLine();
}


Read More..

Sabtu, 23 April 2016

C Program to Print ASCII values and characters using a while loop

C# Program to Print ASCII values and their equivalent characters using a while loop

Problem Statement:
Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.

Solution:
static void Main(string[] args)
{
int i=0;
Console.WriteLine("ASCII Char");
while (i <= 255)
{
Console.WriteLine(i+" "+(char)i);
i++;
}
Console.ReadLine();
}


Read More..

Senin, 18 April 2016

C Program to count total characters entered by users

C# Program to Print Entering Characters from users and then Count Total entering characters 

Program Statement:
Write a program which takes characters from user until user press ENTER and then program will show the number of words with length greater than or equal to 5.

Solution:
public class length
{
int count1 = 0, count2 = 0;
public void check()
{
Console.Write(" Enter string : ");
string ch = Console.ReadLine();
for (int x = 0; x < ch.Length; x++)
{
if (ch[x] == )
{
count1++;
if (x >= 5)
{ count2++; }
}
}
Console.WriteLine(" Number of words with length greater than or equal to 5 : {0}", count2);
Console.WriteLine();
}
}


Read More..