# C # Certification Exam questions.

Source: Internet
Author: User

1.1, enter a positive integer n, if it is an even number to find all the even number within N, and an odd number of N to find all the odd and.

static void Main (string[] args)
{
int result=0;
Console.WriteLine ("Please enter a positive integer:");
int n = Convert.ToInt32 (Console.ReadLine ());
if (n%2==0)
{
for (int i = 0; I <= N; i++)
if (i% 2 = = 0)
result + = i;
}
Else
{
for (int i = 0; I <= N; i++)
if (i% 2! = 0)
result + = i;
}
Console.WriteLine ("Result: {0}", result);

}

1.2. Enter a positive integer to output all the approximate numbers.

static void Main (string[] args)
{
Console.WriteLine ("Please enter a positive integer:");
int n = Convert.ToInt32 (Console.ReadLine ());
if (n% 2 = = 0)
{
for (int i = 2; I <= n/2; i++)
{
if (n% i = = 0)
{
Console.WriteLine (i);
}
}
}
Else
{
for (int i=3;i<= (n-1)/2;i++)
{
if (n%i==0)
{
Console.WriteLine (i);
}
}
}
}

1.3-1.4, enter two positive integers, seek greatest common divisor, least common multiple.

static void Main (string[] args)
{
int result=1;
Console.WriteLine ("Please enter the first positive integer:");
int a = Convert.ToInt32 (Console.ReadLine ());
int x = A;
Console.WriteLine ("Please enter a second positive integer:");
int b = Convert.ToInt32 (Console.ReadLine ());
int y = b;
if (a > B)
{
int t = A;
A = b;
b = t;

}
while (true)
{

if (b% A = = 0)
{
result = A;
Break
}
Else
{
int ys = b% A;
b = A;
A = ys;
}

}
int RESULT1 = x * y/result;
Console.WriteLine ("Greatest common divisor for: {0}", result);
Console.WriteLine ("Least common multiple: {0}", RESULT1);

}

1.5, judge the prime number.

static void Main (string[] args)
{
BOOL Prime=true;
Console.WriteLine ("Please enter a positive integer:");
int n = Convert.ToInt32 (Console.ReadLine ());
for (int i=2;i<=n/2;i++)
{
if (n% i = = 0)
Prime = false;
Break
}
if (prime)
Console.WriteLine ("{0} is a prime number", N);
Else
Console.WriteLine ("{0} is not a prime number", N);
}

1.6.

1.9. Find the most ASCII characters in a string

static void Main (string[] args)

{

String s_text = Convert.ToString (Console.ReadLine ());

Char ch;

ch = s_text[0];

for (int i = 0; i < S_text. Length; i++)

{

if (Ch < s_text[i])

ch = s_text[i];

}

Console.WriteLine ("ASCII maximum character is {0}", ch);

}

1.10. find the smallest ASCII character in a string

static void Main (string[] args)

{

String s_text = Convert.ToString (Console.ReadLine ());

Char ch;

ch = s_text[0];

for (int i = 0; i < S_text. Length; i++)

{

if (Ch > s_text[i])

ch = s_text[i];

}

Console.WriteLine ("ASCII minimum character is {0}", ch);

}

1.11. Enter the original string and the key string, and output the result of encrypting the string.

static void Main (string[] args)
{
String S_text, S_key;
string s_result = null;
Char ch;
Console.WriteLine ("Please enter the original string:");
Console.WriteLine ("Please enter the key string:");
if (S_text. Length! = S_key. Length)
{
Console.WriteLine ("The key string must be equal to the original string length!") ");
}
Else
{
for (int i=0;i<s_text. length;i++)
{
ch = s_text[i];
S_result + = ch ^ s_key[i];

}
Console.Write ("The string after encryption is:");

}
Console.WriteLine (S_result);
}

int x = Convert.ToInt32 (id[18]);

C # Certification Exam questions.

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.