0% found this document useful (0 votes)
17 views

Welcome to Word

The document is a C# program that demonstrates various input and output operations, including reading user inputs for different data types such as strings, integers, doubles, DateTime, and TimeSpan. It also covers data type conversions, Fibonacci sequence generation, palindrome checking, factorial calculation, Armstrong number verification, and binary conversion. Additionally, it includes examples of array manipulation, such as reversing and sorting arrays.

Uploaded by

vishwathirty3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Welcome to Word

The document is a C# program that demonstrates various input and output operations, including reading user inputs for different data types such as strings, integers, doubles, DateTime, and TimeSpan. It also covers data type conversions, Fibonacci sequence generation, palindrome checking, factorial calculation, Armstrong number verification, and binary conversion. Additionally, it includes examples of array manipulation, such as reversing and sorting arrays.

Uploaded by

vishwathirty3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

C# Programme

using System;
using System.Collections.Generic;

using System.Collections;

using System.Linq;

using System.Text;

namespace

class Program

static void Main(string[] args)

INput
//Console.WriteLine("Enter your name:");
string name = Console.ReadLine();
// Getting int input Console.WriteLine("Enter your number:");
int number = int.Parse(Console.ReadLine());
// Getting char input Console.WriteLine("Enter a character:");
char character = char.Parse(Console.ReadLine());
// Getting double input Console.WriteLine("Enter a decimal number:");
double decimalNumber = double.Parse(Console.ReadLine());
//Console.WriteLine("Enter a date (yyyy-mm-dd):");

DateTime date = DateTime.Parse(Console.ReadLine());

// Getting time input Console.WriteLine("Enter a time (HH:mm:ss):");


TimeSpan time = TimeSpan.Parse(Console.ReadLine());

1. Converting String to Integer and Vice Versa

String to Integer:

string strNumber = "123";


int intNumber = int.Parse(strNumber);

Integer to String:

int intNumber = 123;


string strNumber = intNumber.ToString();

2. Converting String to Double and Vice Versa

String to Double:

string strDouble = "123.45";


double doubleNumber = double.Parse(strDouble);

Double to String:

double doubleNumber = 123.45;


string strDouble = doubleNumber.ToString();

3. Converting String to DateTime and Vice Versa

String to DateTime:

string strDate = "2023-07-16";


DateTime date = DateTime.Parse(strDate);

DateTime to String:

DateTime date = DateTime.Now;


string strDate = date.ToString("yyyy-MM-dd");

4. Converting String to TimeSpan and Vice Versa

String to TimeSpan:

string strTime = "12:30:00";


TimeSpan time = TimeSpan.Parse(strTime);

TimeSpan to String:
TimeSpan time = new TimeSpan(12, 30, 0);
string strTime = time.ToString();

5. Converting DateTime to TimeSpan

Subtracting Two DateTimes to Get TimeSpan:

DateTime startDate = new DateTime(2023, 7, 16, 8, 0, 0);


DateTime endDate = new DateTime(2023, 7, 16, 12, 30, 0);
TimeSpan duration = endDate - startDate;

int[] i = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, };


List<int> k=new List<int>();
int j;
for (j=0; j<i.Length; j++)
{
k.Add(i[j]);

}
foreach (int x in k )
{
if (x > 5)
{
Console.WriteLine(x);
}
}

//

K.Contains();
Sort();
Insert()/InsertRange();
Remove()/RemoveRange();

////

string result = string.Empty;

public static void Main()


{
int[] i = { 1, 2, 3 };
int j;
string result = string.Empty;
for (j = i.Length - 1; j >= 0; j--)
{
result = result + i[j] + ",";
}
Console.WriteLine(result);
}

--------------------------------------------------------
fibonaci
int i, count, a = 0, b = 1, c = 0;

Console.Write("Enter a limit number;");

count =int.Parse(Console.ReadLine());

Console.Write(a);
Console.Write(b);
for (i = 0; i <= count; i++) {

c = a + b;
Console.Write(c + " ");

a=b;
b=c;

swap;
a=10,b = 30;

a = a + b //a=40
b = a - b; //b=10
a = a - b; //a=30
(or)
a=a*b;
b=a/b;
a=a/b;

-------------------------------------------------------------
palindrome;

while (n > 0)
{
i=n%10;
m = (m * 10) + i;
n =n/10;
}/

-------------------------------------------------------------

Factorial;

for(i=1;i<=number;i++){
fact=fact*i;
}
-------------------------------------------------------------

Armstrong Number ;

while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}

-------------------------------------------------------------

Sum of digit;

while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
Console.Write("Sum is= "+sum);

-------------------------------------------------------------

reverse number;

while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}

-------------------------------------------------------------

convert Decimal to Binary

int n, i;
int[] a = new int[10];
Console.Write("Enter the number to convert: ");
n = int.Parse(Console.ReadLine());
for (i = 0; n > 0; i++)
{
a[i] = n % 2;
n = n / 2;
}
Console.Write("Binary of the given number= ");
for (i = i - 1; i >= 0; i--)
{
Console.Write(a[i]);
}

---------------------------------------------------

how to write on reverse in numbers;

public class Program


{
static void Main(string[] args)
{
//Creating an Integer Array
int[] arr = { 1, 2, 3, 4, 5 };
Console.Write("Original Array Elements1 :");
for (int i = 0; i <=arr.Length-1; i++)
{
Console.Write(arr[i] + " ");
}
for (int j = arr.Length; j >0; j--)
{
Console.Write(arr[j-1] + " ");
}
}
}

------------------------------------------------------

Array Short

static void Main(string[] args)


{
int[] arr = { 7, 1, 3, 2 };
Array.Sort(arr);
Console.Write("Original Array Elements: ");
foreach (var element in arr)
{
Console.Write(element + " ");
}
}
------------------------------------------------------------

You might also like