Sie sind auf Seite 1von 6

namespace Exercise_1

{
class Prime
{
public void Prime_Number(int number)
{
int i;
for (i = 2; i < number; i++)
{
if (number % i == 0)
{
Console.WriteLine("{0} is not a prime number", number);
break;
}
}
if (i == number)
{
Console.WriteLine("{0} is a prime number", number);
}
}

static void Main(string[] args)


{
int num;
Console.WriteLine("Enter the number: ");
num = Convert.ToInt32(Console.ReadLine());
Prime p = new Prime();
p.Prime_Number(num);
Console.ReadKey();
}
}
}
................................................................................
.....................................
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

static class WordTools


{
/// <summary>
/// Receive string of words and return them in the reversed order.
/// </summary>
public static string ReverseWords(string sentence)
{
string[] words = sentence.Split(' ');
Array.Reverse(words);
return string.Join(" ", words);
}
}

class Program
{
static void Main()
{
const string s1 = "Bill Gates is the richest man on Earth";
const string s2 = "Srinivasa Ramanujan was a brilliant mathematician";

string rev1 = WordTools.ReverseWords(s1);


Console.WriteLine(rev1);
string rev2 = WordTools.ReverseWords(s2);
Console.WriteLine(rev2);
Console.ReadKey();
}
}
................................................................................
..........................................
class ReverseString
{
public static void Main(string[] args)
{
string Name = "He is palying in a ground.";
char[] characters = Name.ToCharArray();
StringBuilder sb = new StringBuilder();
for (int i = Name.Length - 1; i >= 0; --i)
{
sb.Append(characters[i]);
}
Console.Write(sb.ToString());
Console.Read();
}
}
................................................................................
........................................
namespace Triangle
{
class Program
{
static void Main(string[] args)
{
var triangle = "*";
do
{
Console.WriteLine(triangle);
}
while ((triangle += "*").Length < 10);
Console.ReadLine();
}
}
}

................................................................................
...........................................
namespace Pyramid
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Enter the Height of the Pyramid: ");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
for (int j = n; j >= i; j--)
{
Console.Write(" ");
}
for (int k = 1; k <= i; k++)
{
Console.Write("*");
}
for (int m = 2; m <= i; m++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
................................................................................
..................................................
using System;
class Program
{
static void Main()
{
string[] a = new string[]
{
"Egyptian",
"Indian",
"American",
"Chinese",
"Filipino",
};
Array.Sort(a);
foreach (string s in a)

{
Console.WriteLine(s);
}
}
}
................................................................................
....................................................
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = string.Empty;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property
for (int j = i - 1; j >= 0; j--)
{
str = str + s[j];
}
if (str == s)
{
Console.WriteLine(s + " is palindrome");
}
else
{
Console.WriteLine(s + " is not a palindeome");
}
Console.WriteLine(str);
Console.Read();

}
}
}
................................................................................
..............................................................
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{

Console.Write("Please Enter the Year: ");


int year = int.Parse(Console.ReadLine());
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
Console.WriteLine("The year {0}, is a Leap Year", year);
}
else
{
Console.WriteLine("The year {0}, is not a Leap Year", year);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
................................................................................
................................................................
namespace Pyramid
{
class ReverseString
{
public static void Main(string[] args)
{
string Name = "He is palying in a ground.";
char[] characters = Name.ToCharArray();
string[] a = Name.Split(' ');
Array.Reverse(a);
Console.WriteLine(string.Join(" ",a));
StringBuilder sb = new StringBuilder();
for (int i = Name.Length - 1; i >= 0; i--)
{
sb.Append(characters[i]);
}
Console.Write(sb.ToString());
Console.Read();
}
}
}
................................................................................
...................................................
namespace MyApp
{
class Armstrong_class
{
static void Main(string[] args)
{
int number, _num, sum = 0;
Console.WriteLine("Enter a Number");
number = Convert.ToInt32(Console.ReadLine());
for (int i = number; i > 0; i = i / 10)
{

_num = i % 10;
sum = sum + _num * _num * _num;
}
if (sum == number)
Console.WriteLine("The Number is Armstrong Number");
else
Console.WriteLine("The Number is not a Armstrong Number");
Console.ReadLine();
}
}
}
................................................................................
................................................
Fibonacci
static void Main(string[] args)
{
int previous = -1; int next = 1;
int position;
Console.WriteLine("Enter the position");
position = int.Parse(Console.ReadLine());
for (int i = 0; i < position; i++)
{
int sum = next + previous; previous = next;
next = sum;
Console.WriteLine(next);
}
Console.ReadLine();
}

Write a program in JavaScript that removes numbers present in a given sentence


Write a java script to identify the numbers from the give string
write a javascript code to delete duplicate string

Das könnte Ihnen auch gefallen