Tampilkan postingan dengan label values. Tampilkan semua postingan
Tampilkan postingan dengan label values. Tampilkan semua postingan

Sabtu, 28 Mei 2016

C Program which takes n values from user and then sort them using Bubble sort

,
C# Program which takes n values from user and then sort them using Bubble sort

Program Statement:
Write a program which takes n values from user and then sort them using Bubble sort

Solution:
 public class bubble
{
int n, x, y, z;
public void sort()
{
System.Console.Write(" Enter length of array : ");
n = Convert.ToInt32(System.Console.ReadLine());
int[] array = new int[n + 1];
int[] temp1 = new int[n + 1];
int[] temp2 = new int[n];
System.Console.WriteLine(" Enter {0} numbers : ", n);
for (x = 0; x < n; x++)
{
array[x] = Convert.ToInt32(System.Console.ReadLine());
}
for (y = n; y > 0; y--)
{
for (z = 0; z < y; z++)
{
if (array[z] > array[z + 1])
{
temp1[z] = array[z];
array[z] = array[z + 1];
array[z + 1] = temp1[z];
temp2[z] = array[z + 1];
}
else
{ temp2[z] = array[z]; }
}
}
Console.WriteLine(" >>>Ordered List<<< ");
for (int i = 0; i < n; i++)
{
Console.WriteLine(" {0}", temp2[i]);
}
}
}


Read more

Rabu, 04 Mei 2016

C Program which takes n values from user and then sort them in ascending order

,
C# Program which takes n values from user and then sort them in ascending order

Program Statement:
Write a program which takes n values from user and then sort them in ascending order.

Solution:
 public class sort
{
int n, x, y, z;
public void s()
{
Console.Write(" Enter number of values you want to sort : ");
n = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write(" Enter number : ");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
for (x = 0; x < n; x++)
{
for (y = x + 1; y < n; y++)
if (arr[x] > arr[y])
{
int temp;
temp = arr[y];
arr[y] = arr[x];
arr[x] = temp;
}
}
Console.WriteLine(" >>>Ascending Order<<< ");
for (z = 0; z < n; z++)
{
Console.WriteLine(" {0}", arr[z]);
}
}
}


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

Rabu, 13 April 2016

C Program to Print ASCII Values Using do while Loop

,
C# Program to Print ASCII Values Using do-while Loop

Program Statement:
Write a program to print all the ASCII values and their equivalent characters using a do-while loop. The ASCII values vary from 10 to 255.

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


Read more

Jumat, 08 April 2016

C Program which copies the values of one array in second array in reverse order

,
C# Program which copies the values of one array in second array in reverse order

Program Statement:
Write a program which copies the values of one array in second array in reverse order

Solution:
 public class reverse
{
int n;
public void rev()
{
Console.Write(" Enter length of array : ");
n = Convert.ToInt32(Console.ReadLine());

int[] arr1 = new int[n];
int[] arr2 = new int[n];

Console.WriteLine(" Enter {0} numbers : ", n);
for (int x = 0; x < n; x++)
{ arr1[x] = Convert.ToInt32(Console.ReadLine()); }

Console.Write(" Reversed element : ");
for (int y = n - 1; y >= 0; y--)
{ arr2[(n - 1) - y] = arr1[y]; }
for (int z = 0; z < n; z++)
{ Console.Write(" {0}", arr2[z]); }
Console.WriteLine(" ");
}
}


Read more

Kamis, 17 Maret 2016

C Program to Print number of prime values in the array

,
C# Program to Print number of prime values in the array

Program Statement:
Write a program which takes 10 values from user in an array and then show the number of prime values in the array.

Solution:
 public class arr
{
int c, count = 0, n;
int[] array = new int[10];
public void arr_func()
{
Console.WriteLine(" Enter 10 element only! ");
for (int x = 0; x < 10; x++)
array[x] = Convert.ToInt32(Console.ReadLine());
for (int y = 0; y < 10; y++)
{
n = array[y];
for (c = 2; c <= n - 1; c++)
{
if (n % c == 0)
{ break; }
}

if (c == n)
{
count++;
Console.WriteLine(" {0} is prime number! ", n);
}
}
Console.WriteLine(" Number of prime values : {0} ", count);
}
}


Read more
 

Make Money Online Now Free Copyright © 2016 -- Powered by Blogger