C# Fundamentals Programs

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

1.

Array 1 : (100)

using System;

namespace LearnCsharp

class FindMaxMinAge{

public static void Main(string[] args) {

int i,j,n,tem;

n=Convert.ToInt32(Console.ReadLine());

if((n>=1)&&(n<=20))

int[] a=new int[n];

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{

public static void Main(string[] args) {

int n;

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

int[] nums = new int[n];


if(n < 2 || n > 20)

Console.WriteLine("INVALID_INPUT");

return;

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

nums[i] = int.Parse(Console.ReadLine());

if(n % 2 != 0)

Array.Sort(nums);

Array.Reverse(nums);

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

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("");

3. Conditional statements 2: (100)

using System;

namespace LearnCsharp

class Rightangletriangle{

public static void Main(string[] args) {

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

Console.WriteLine("NOT RIGHT ANGLE TRIANGLE");

else

Console.WriteLine("INVALID_INPUT");

}
4. Loop 3:( 100)

using System;

namespace LearnCsharp

class Armstrongnumber{

static int power(int n, int r)

int p=1,i;

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

p=p*n;

return p;

public static void Main(String[] args)


{

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{

public static void Main(string[] args) {

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{

public static void Main(string[] args) {

//CODE START

string answer;

string result;

answer = Console.ReadLine();

int num = Convert.ToInt32(answer);

result = "";
if(num>1&&num<999)

while (num > 1)

int remainder = num % 2;

result = Convert.ToString(remainder) + result;

num /= 2;

result = Convert.ToString(num) + result;

Console.WriteLine("{0}", result);

else{

Console.WriteLine("INVALID_INPUT");

//CODE END

7. Loop 2: (100)

using System;

namespace LearnCsharp

{
class Sumofprimenumbers{

public static void Main(string[] args) {

//CODE START

int num,i,ctr,stno,enno,sum=0;

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

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

if(stno>enno || stno<3 || enno<3){

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;

if(ctr==0 && num!= 1){

sum=sum+num;

}
Console.Write(sum);

//CODE END

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy