Sunteți pe pagina 1din 17

# 1.

## Write a C# Sharp program to print Hello and your name in a

separate line.
public class Exercise1
{
public static void Main( )
{
System.Console.WriteLine("Hello");
System.Console.WriteLine("Alexandra Abramov!");
}
}
2. Write a C# Sharp program to print the sum of two numbers.
public class Exercise2
{
public static void Main()
{
System.Console.WriteLine(15+17);
}
}

using System;

## Console.Write("\nInput the Second Number : ");

temp = number1;
number1 = number2;

number2 = temp;

## 4. Write a C# Sharp program that takes four numbers as input to

calculate and print the average
using System;

## public static void Main()

int number1,number2,number3,number4;

## Console.Write("Enter the four number: ");

int result = (number1 + number2 + number3 + number4) / 4;

Fahrenheit
using System;

## 6. Write a C# Sharp program that takes three letters as input and

display them in reverse order.
using System;

## public static void Main()

char letter,letter1,letter2;
Console.Write("Input letter: ");

even or odd.
using System;

## int num1, rem1;

Console.Write("\n\n");

## Console.Write("Check whether a number is even or odd :\n");

Console.Write("---------------------------------------");

Console.Write("\n\n");

rem1 = num1 % 2;
if (rem1 == 0)

else

numbers.
using System;

## public static void Main()

int j, sum = 0;

Console.Write("\n\n");

## Console.Write("Find the sum of first 10 natural numbers:\n");

Console.Write("----------------------------------------------");

Console.Write("\n\n");

## for (j = 1; j <= 10; j++)

sum = sum + j;

Console.Write("{0} ",j);

## Console.Write("\nThe Sum is : {0}\n", sum);

}
9. Write a program in C# Sharp to store elements in an array and print
it.
using System;

int i;

## Console.Write("\n\nRead and Print elements of an array:\n");

Console.Write("-----------------------------------------\n");

## Console.Write("{0} ", arr[i]);

Console.Write("\n");

}
10. Write a program in C# Sharp to find the sum of all elements
of the array.
using System;

int i, n, sum=0;

## Console.Write("\n\nFind sum of all elements of array:\n");

Console.Write("--------------------------------------\n");

array :");

for(i=0;i<n;i++)

## for(i=0; i<n; i++)

sum += a[i];

}
Console.Write("Sum of all elements stored in the array is : {0}\n\n",
sum);

## 11. Write a program in C# Sharp to copy the elements one array

into another array.
using System;

int i, n;

## Console.Write("\n\nCopy the elements one array into another array

:\n");

Console.Write("----------------------------------------------------\n");

array :");

for(i=0;i<n;i++)

## for(i=0; i<n; i++)

arr2[i] = arr1[i];

## Console.Write("{0} ", arr2[i]);

Console.Write("\n\n");

using System;

## public class Exercise1

{
public static void Main()

string str;

## Console.Write("\n\nAccept a string from keyboard :\n");

Console.Write("-----------------------------------\n");

## 13. Write a program in C# Sharp to find the length of a string

without using library function.
using System;

int l= 0;

## Console.Write("\n\nFind the length of a string :\n");

Console.Write("---------------------------------\n");

{
l += 1;

using System;

class funcexer1

## public static void welcome()

Console.WriteLine("Welcome Friends!");

## Console.Write("\n\nSee, how to create an user define function :\n");

Console.Write("------------------------------------------------\n");

welcome();

HaveAnice();

Console.Write("\n");
}

## 15. Write a program in C# Sharp to find the factorial of a given

number using recursion
using System;

class RecExercise9

## Console.WriteLine("\n\n Recursion : Find the factorial

of a given number :");

Console.WriteLine("-------------------------------------------------------");

## private static long FactorialCalcu(int n1)

if (n1 == 0)

return 1;

return n1 * FactorialCalcu(n1-1);
}

## 16. Write a program in C# Sharp to find the Fibonacci numbers

for a n numbers of series using recursion.
using System;

class RecExercise10

int p = 0;

int q = 1;

int temp = p;

p = q;

q = temp + q;

return p;

## Console.WriteLine("\n\n Recursion : Find the Fibonacci numbers for a n

numbers of series :");

Console.WriteLine("-----------------------------------------------------------
------------");
Console.Write(" Input number of terms for the Fibonacci series
: ");

## for (int i = 0; i < n1; i++)

Console.Write("{0} ",FindFibonacci(i));

## 17. Write a C# Sharp program to extract the Date property and

display the DateTime value in the formatted output.
using System;

## Console.WriteLine("Display date using 24-hour clock format:");

Console.WriteLine(dateOnly.ToString("g"));
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"));

## 18. Write a program in C# Sharp to remove a file from the disk.

using System;

using System.IO;

using System.Text;

class filexercise1

## Console.Write("\n\n Remove a file from the disk (at

first create the file ) :\n");

Console.Write("--------------------------------------------------------------\
n");

## // Delete the file if it exists.

if (File.Exists(fileName))

File.Delete(fileName);

## Console.WriteLine(" The file {0} deleted

successfully.\n\n",fileName);

else

## 19. Write a program in C# Sharp to create a file with text and

using System;

using System.IO;

using System.Text;

class filexercise3

try

## // Delete the file if it exists.

if (File.Exists(fileName))

File.Delete(fileName);

## Console.Write("\n\n Create a file with text and read

the file :\n");

Console.Write("-------------------------------------------------\n");

{

string s = "";

## Console.WriteLine(" Here is the content of the

file mytest.txt : ");

## while ((s = sr.ReadLine()) != null)

Console.WriteLine(s);

Console.WriteLine("");

## catch (Exception MyExcep)

Console.WriteLine(MyExcep.ToString());

20.
21.
22.