C# Fundamentals Programs
C# Fundamentals Programs
C# Fundamentals Programs
Array 1 : (100)
using System;
namespace LearnCsharp
class FindMaxMinAge{
int i,j,n,tem;
n=Convert.ToInt32(Console.ReadLine());
if((n>=1)&&(n<=20))
for(i=0;i<n;i++)
a[i]=Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
for(j=i;j<n;j++)
if(a[i]>a[j])
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
Console.WriteLine("MIN={0}",a[0]);
Console.WriteLine("MAX={0}",a[n-1]);
else
Console.WriteLine("INVALID_INPUT");
2. Array 2: (100)
using System;
using System.Linq;
using System.Collections.Generic;
namespace LearnCsharp
class Sortnumbers{
int n;
n = int.Parse(Console.ReadLine());
Console.WriteLine("INVALID_INPUT");
return;
nums[i] = int.Parse(Console.ReadLine());
if(n % 2 != 0)
Array.Sort(nums);
Array.Reverse(nums);
Console.Write(nums[i]);
Console.Write("");
if(n % 2 == 0)
Array.Sort(nums);
for(int i = 0; i < n; i ++)
Console.Write(nums[i]);
Console.Write("");
using System;
namespace LearnCsharp
class Rightangletriangle{
int a,b,c;
a=Convert.ToInt32(Console.ReadLine());
b=Convert.ToInt32(Console.ReadLine());
c=Convert.ToInt32(Console.ReadLine());
if((a>=b)&&(a>=c))
if((a*a)==(b*b)+(c*c))
{
Console.WriteLine("RIGHT ANGLE TRIANGLE");
else
else
Console.WriteLine("INVALID_INPUT");
}
4. Loop 3:( 100)
using System;
namespace LearnCsharp
class Armstrongnumber{
int p=1,i;
for(i=0;i<r;i++)
p=p*n;
return p;
int n,r=0,rem,rev=0,tem,tem1;
n=Convert.ToInt32(Console.ReadLine());
tem=n;
tem1=n;
while(tem!=0)
tem=tem/10;
r++;
if(r==3)
while(n!=0)
rem=n%10;
rev+=power(rem,r);
n=n/10;
if(tem1==rev)
Console.WriteLine("ARMSTRONG");
else
Console.WriteLine("NOT ARMSTRONG");
}
else
Console.WriteLine("INVALID_INPUT");
5. Conditional 1: (100)
using System;
namespace LearnCsharp
class StudentsGrade{
int a,b,c,avg;
a=Convert.ToInt32(Console.ReadLine());
b=Convert.ToInt32(Console.ReadLine());
c=Convert.ToInt32(Console.ReadLine());
avg=(a+b+c)/3;
if((a>=1)&&(a<=100)&&(b>=1)&&(b<=100)&&(c>=1)&&(c<=100))
if(avg>=70)
Console.WriteLine("DISTINCTION");
else if(avg>=60)
Console.WriteLine("FIRST");
else if(avg>=50)
Console.WriteLine("SECOND");
else if(avg>=40)
Console.WriteLine("THIRD");
else
Console.WriteLine("FAIL");
else
Console.WriteLine("INVALIDMARKS");
6. Loop 1: (100)
using System;
namespace LearnCsharp
class Decimaltobinary{
//CODE START
string answer;
string result;
answer = Console.ReadLine();
result = "";
if(num>1&&num<999)
num /= 2;
Console.WriteLine("{0}", result);
else{
Console.WriteLine("INVALID_INPUT");
//CODE END
7. Loop 2: (100)
using System;
namespace LearnCsharp
{
class Sumofprimenumbers{
//CODE START
int num,i,ctr,stno,enno,sum=0;
stno= int.Parse(Console.ReadLine());
enno= int.Parse(Console.ReadLine());
Console.Write("INVALID_INPUT");
else{
for(num = stno;num<=enno;num++)
ctr = 0;
for(i=2;i<=num/2;i++)
if(num%i==0){
ctr++;
break;
sum=sum+num;
}
Console.Write(sum);
//CODE END