Pages

Tampilkan postingan dengan label iteration. Tampilkan semua postingan
Tampilkan postingan dengan label iteration. Tampilkan semua postingan

Senin, 09 Mei 2016

C program to print nth iteration using loops

C# program to print 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 . . . nth iteration

Problem Statement:
Write a program using loop which prints the following output.
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 . . . nth iteration

Solution:
static void Main(string[] args)
{
int i, j, num;
Console.WriteLine("Enter value of num:");
num = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= num; i++)
{
for (j = 1; j <= i; j++)
Console.Write(i + " ");
}
Console.ReadLine();
}


Read More..

Jumat, 29 April 2016

C program to print nth iteration Csharp Programs

C# program to print 1 2 4 8 16 21 64 128 …nth iteration

Program Statement:
Write a program using for loop which prints the following series.
1 2 4 8 16 21 64 128 …nth iteration

Solution:

static void Main(string[] args)
{
int n,i=1,num=1;
Console.WriteLine("Enter Value of n ");
n = Convert.ToInt32(Console.ReadLine());
Console.Write(i+" ");
for (i = 1; i <= n; i++)
{
num = num * 2;
Console.Write(num + " ");
}

Console.ReadLine();
}


Read More..