Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

// See https://aka.

ms/new-console-template for more information


using System;
public class Sample
{
public static void Main(string[] args)
{
int a = 1;
int b = 2;
int c = a + b;
c = a * b;
c = a / b;
c = a % b;
c = a + b;
Console.WriteLine(c);
for (int i = 0; i < c; i++)
{
Console.WriteLine(i);
}
Console.WriteLine($"{Environment.NewLine}");
while (c > 0)
{
Console.WriteLine(c);
c--;
}
int x = 10;
int y = x++;
Console.WriteLine("a={0}, b{1}", x, y);

//unboxing

object aa = 10;
int bb = (int)aa;
Console.WriteLine("a={0}", bb);
//boxing
int aaa = 10;
object bbb = aaa;

System.Console.WriteLine("Hello, World!");
Console.WriteLine("first num:?");
var num = int.Parse(Console.ReadLine());
Console.WriteLine("second num:?");
int num2 = Convert.ToInt32(Console.ReadLine());

var date = DateTime.Now;


Console.WriteLine($"{Environment.NewLine}first: {num},
{Environment.NewLine}second:{num2}, {Environment.NewLine}date{date}on !");
String ab = Convert.ToString(num2);
Console.WriteLine($"a datatype is:{ab} : "+ ab.GetType());
Console.WriteLine($"num datatype is:{ num} : "+num.GetType());
Console.WriteLine("a={0},b={1},c={2}", num, num2, a);

//escape sequence
String name = "hello1 \n hello2";
String name1 = "\"hello\"";
String name2 = "c:\\downloads\\program";
Console.WriteLine(name2);
//c:\downloads\program
String name3 = @"c:\\downloads\\program";
// c:\\downloads\\program
Console.WriteLine(name3);
Console.WriteLine(name1 +"\n"+ name);
//o/p : name1="hello", name= hello1
//hello2
}
}

// See https://aka.ms/new-console-template for more information


using System;
public class LowerorUpper
{
public static void Main(string[] args)
{
//EXPLICIT TYPE CATSING
float f = 28497473498714987.324f;
int i = (int)f;
Console.WriteLine(i);//-2147483648
// int j = Covert.ToInt32(f);
//ERROR

int ii = 212;
float ff = (float)i;//-2.1474836E+09
Console.WriteLine(ff);

//IMPLICIT TYPE CASTING


float fff = 212.323;
int a=(int )fff;
Console.WriteLine(a);

}
}

using System;
public class LowerorUpper
{
public static void Main(string[] args)
{
String s = "56365hgd";
bool b= int.TryParse(s, out int result);
Console.WriteLine(b);//false
Console.WriteLine(result);
//NULL COLIZING OPERATOR ='?'
int? x =null;
//int? y = x;
Console.WriteLine(x??20);
//Console.WriteLine("x is : " + y);

}
}

using System;
public class guess
{
public static void Main(string[] args)
{
int count = 0;
int target = 10;
Random ran = new Random();
int i = ran.Next(1,101);
while (i != target && i>0 && i<101 )
{
count++;
Console.WriteLine("guess the num " + count+ "time\n");
i=int.Parse(Console.ReadLine());
if(count== 5)
{
break;
}
else if (i == target)
{
break;
}
else if (i < target)
{
Console.WriteLine("less than target");
}
else
{
Console.WriteLine("greater than target");
}
}
Console.WriteLine("target achived target is :" + target + "count is :" +
count);

}
}

//LEAP YEAR

using System;
public class guess
{
public static void Main(string[] args)
{
Console.WriteLine("enter a year");
int yr = int.Parse(Console.ReadLine());
int leap = yr % 4;
int lp = yr % 100;
int l = yr % 400;
if (leap == 0 && lp != 0 || l==0)
Console.WriteLine("leap year");
else
Console.WriteLine("not a leap");
}
}

using System;
public class Guess
{
public static void Main(string[] args)
{
Console.Out.WriteLine("enter the wieght");
float w = float.Parse(Console.ReadLine());
Console.Out.WriteLine("enter the height");
float h = (float)Convert.ToDouble(Console.ReadLine());
h = (float)(h * 0.3048);
float bmi = w / (h * h);
Console.Out.WriteLine("BMI of the given person with wieght : "
+ w + ",height : " + h + " BMI is ={0}" +
bmi,bmi);
if (bmi < 18.5)
Console.Out.WriteLine("under weight");
else if (bmi > 18.5 && bmi < 24.9)
Console.Out.WriteLine("healthy weight");
else if (bmi > 30)
Console.Out.WriteLine("obesity");
else
Console.Out.WriteLine("over weight");
}
}

// See https://aka.ms/new-console-template for more information


using System;

public class Guess


{
public static void Main(string[] args)
{
bool upper = false;
bool lower = false;
bool num = false;
bool spl = false;
Console.WriteLine("enter the password");
String str = Console.ReadLine();

for (int i = 0; i < str.Length - 1; i++)


{
if (Char.IsUpper(str[i]))
upper = true;
else if (Char.IsLower(str[i]))
lower = true;
else if (Char.IsDigit(str[i]))
num = true;
else if (str[i] == '+'|| str[i] =='-'|| str[i] =='_'|| str[i] =='='||
str[i] =='@'|| str[i] =='$'||str[i] =='.')
spl = true;
}
if (upper && lower && num && spl&&str.Length>8)
Console.WriteLine("strong password");
else if (upper && lower && num)
Console.WriteLine("moderate password");
else
Console.WriteLine("weak password");
}
}

You might also like