Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
66 views

This Program Is To Swap Two Integers // Kindly Change The Variable Names Before Copying The Program in Your Files

This document contains code for 4 C# programs: 1. A program to swap two integers by assigning one variable to the other and vice versa. 2. A program to find the greatest of three integers input by the user. 3. A program to find all Armstrong numbers between 1 and 500. 4. A program to output the first n terms of the Fibonacci series for a user-input n.

Uploaded by

Ankur Jain
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)
66 views

This Program Is To Swap Two Integers // Kindly Change The Variable Names Before Copying The Program in Your Files

This document contains code for 4 C# programs: 1. A program to swap two integers by assigning one variable to the other and vice versa. 2. A program to find the greatest of three integers input by the user. 3. A program to find all Armstrong numbers between 1 and 500. 4. A program to output the first n terms of the Fibonacci series for a user-input n.

Uploaded by

Ankur Jain
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/ 5

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;


// this program is to swap two integers
// KINDLY CHANGE THE VARIABLE NAMES BEFORE COPYING THE PROGRAM IN YOUR FILES

namespace file_program_day2
{
class Program
{
static void Main(string[] args)
{
int a, b, temp;
Console.WriteLine("Enter any two numbers ");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
Console.Write("Numbers before swapping are ");
Console.Write(a);
Console.Write(" and ");
Console.WriteLine(b);
temp = a;
a = b;
b = temp;
Console.Write("Numbers after swapping are ");
Console.Write(a);
Console.Write(" and ");
Console.WriteLine(b);
}
}
}














using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

////////////////////////////// program to check greatest integer aming three

///////////////////////////// KINDLY CHANGE THE VARIABLE NAMES BEFORE COPYING THE PROGRAM
IN YOUR FILES

namespace file_program1_day2
{
class Program
{
static void Main(string[] args)
{
int a, b, c;
Console.Write("Enter any three integers ");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
if (a > b && a > c)
{
Console.Write("Greatest integer is ");
Console.WriteLine(a);
}
else if (b > c && b > a)
{
Console.Write("Greatest integer is ");
Console.WriteLine(b);
}
else
{
Console.Write("Greatest integer is ");
Console.WriteLine(c);
}
}
}
}










using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//////////////////// program to find armstrong number upto 500

//////////////////// KINDLY CHANGE THE VARIABLE NAMES BEFORE COPYING THE PROGRAM IN YOUR
FILES

namespace file_program2_day2
{
class Program
{
static void Main(string[] args)
{
int t, h, i, tr, hr, num;
for (i = 1; i <= 500; i++)
{
h = i / 100;
hr = i % 100;
t = hr / 10;
tr = hr % 10;
num = (h*h*h)+(t*t*t)+(tr*tr*tr);
if (num == i)
{
Console.Write("Armstrong number is ");
Console.WriteLine(num);
}
}
}
}
}













using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/////////////// this program is to display fibonacci series upto 'n' term

/////////////// KINDLY CHANGE THE VARIABLE NAMES BEFORE COPYING THE PROGRAM IN YOUR FILES


namespace file_program3_day2
{
class Program
{
static void Main(string[] args)
{
int n, first = 0, second = 1, next, c;

Console.WriteLine("Enter the number of terms");
n = int.Parse(Console.ReadLine());
Console.Write("First ");
Console.Write(n);
Console.WriteLine(" terms of Fibonacci series are :-");

for (c = 0; c < n; c++)
{
if (c <= 1)
next = c;
else
{
next = first + second;
first = second;
second = next;
}
Console.WriteLine(next);
}
}
}
}










using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace check1
{
class Program
{
static void Main(string[] args)
{
int i;
Console.Write("Enter a Number : ");
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.Write("Entered Number is an Even Number");
Console.Read();
}
else
{
Console.Write("Entered Number is an Odd Number");
Console.Read();
}
}
}
}



http://chenyichun0407.wordpress.com/2010/05/19/visual-studio-2010-installation-step-by-step/

You might also like