0% found this document useful (0 votes)
17 views4 pages

Experiment3 C#

The document contains four C# programs demonstrating basic algorithms: generating a Fibonacci series, checking for Armstrong numbers, calculating the sum of digits, and determining if a number is a palindrome. Each program prompts the user for input, processes the data, and outputs the result. The code snippets are structured within namespaces and include necessary using directives.

Uploaded by

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

Experiment3 C#

The document contains four C# programs demonstrating basic algorithms: generating a Fibonacci series, checking for Armstrong numbers, calculating the sum of digits, and determining if a number is a palindrome. Each program prompts the user for input, processes the data, and outputs the result. The code snippets are structured within namespaces and include necessary using directives.

Uploaded by

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

Experiment No – 3

Program 1 – Fibonacci Series

Input –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
internal class Program
{
static void Main(string[] args)
{
int i, count, f1 = 0, f2 = 1, f3 = 0;
Console.Write("Enter the limit:");
count = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);

for (i = 0; i <= count; i++) {


f3 = f1 + f2;
Console.WriteLine(f3);
f1 = f2;
f2 = f3;
}
Console.ReadLine();
}
}
}

Output –
Program 2 – Armstrong No

Input –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Armstrong_No
{
internal class Program
{
static void Main(string[] args)
{
int number, remainder, sum = 0;
Console.Write("Eneter the number:");
number = int.Parse(Console.ReadLine());

for(int i = number; i > 0; i = i/10)


{
remainder = i % 10;
sum = sum + remainder*remainder*remainder;
}
if(sum == number)
{
Console.Write("Entered Number is an Armstrong Number");
}

else
{
Console.Write("Entered Number is not an Armstrong Number");
}
Console.ReadLine();
}
}
}

Output –
Program 3 – Sum of Digits

Input –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SumofDigits
{
internal class Program
{
static void Main(string[] args)
{
int num, sum = 0, r;
Console.Write("Enter a number:");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
r = num % 10;
num = num / 10;
sum = sum + r;
}
Console.WriteLine("Sum of Digits:" + sum);
Console.ReadLine();
}
}
}

Output –
Program 4 – Palindrome Number

Input –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Palindromeno
{
internal class Program
{
static void Main(string[] args)
{
int num, r, sum = 0, temp;
Console.Write("Enter a number:");
num = int.Parse(Console.ReadLine());
temp = num;
while (num > 0)
{
r = num % 10;
sum = (sum * 10) + r;
num = num / 10;
}

if(temp == sum)
{
Console.WriteLine("Number is Palindrome");
}

else
{
Console.WriteLine("Number is not palindrome");
}
Console.ReadLine();
}
}
}

Output –

You might also like