κάτι πρόχειρο αλλά δουλεύει νομίζω
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string[] args = new string[2];
args[0] = "username";
args[1] = "password";
int fAttempts = 0;
while (fAttempts <= 3)
{
Console.WriteLine("Username:");
string username = Console.ReadLine();
Console.WriteLine("Password:");
string password = Console.ReadLine();
if (username == args[0] && password == args[1])
{
break; //exit while
}
else { fAttempts++; Console.WriteLine("Login failed invalid credentials!\n"); }
}
if (fAttempts == 3) { Console.WriteLine("Your login attempts limit has been reached, application will now exit!"); Console.ReadLine(); return; } //Exit
int menu = 1;
while (menu != 0)
{
showMenu();
menu = Convert.ToInt32(Console.ReadLine()); //ksanadiavazei
if (menu == 1)
{
Console.WriteLine("Dwse to M:");
int m = Convert.ToInt32(Console.ReadLine());
if (m>0)
{
int sum = 0;
int tSum = 0;
int i;
for (i = 0; i <= m; i++)
{
if (sum >= m) break;
sum = sum * 2 + 1; // ((0x2) + 1 ),(1x2)+1) klp klp
tSum += sum;
// Console.WriteLine(sum + "\n");
}
Console.WriteLine(tSum + "\n");
}
}
else if (menu == 2)
{
Console.WriteLine("Dwse prwto akeraio:");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Dwse deutero akeraio:");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(gcd(a, b));
}
else if (menu == 3)
{
int i = 100;
for (i = 100; i <= 999; i++)
{
int f = (i / 100) % 10;
int s = (i / 10) % 10;
int t = i % 10;
int sum = f + s + t;
if (i % sum == 0) Console.WriteLine(i+",");
}
Console.WriteLine("\n");
}
else if (menu == 0)
{
Console.WriteLine("The application will not exit, you typed 0!");
Console.ReadLine();
return;
}
}
}
static int gcd(int u, int v)
{
// simple cases (termination)
if (u == v)
return u;
if (u == 0)
return v;
if (v == 0)
return u;
// look for factors of 2
if (u%2==0) // u is even
if (v%2==1) // v is odd
return gcd(u >> 1, v);
else // both u and v are even
return gcd(u >> 1, v >> 1) << 1;
if (v%2==0) // u is odd, v is even
return gcd(u, v >> 1);
// reduce larger argument
if (u > v)
return gcd((u - v) >> 1, v);
return gcd((v - u) >> 1, u);
}
static void showMenu()
{
Console.WriteLine("MiniProject C#\n");
Console.WriteLine("1 - Ypologismos Ginomenou");
Console.WriteLine("2 - Megistos Koinos Diairetis");
Console.WriteLine("3 - 3psifioi Arithmoi Harshad");
Console.WriteLine("0 - Exit\n");
Console.Write("Epiloges (1,2,3,or 0): ");
}
}
}
se VS 2008