当前位置:网站首页>C # final review programming question (guessed by the teacher)
C # final review programming question (guessed by the teacher)
2022-06-12 16:52:00 【Vijurria】
1. Judge n Odd or even .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
if (n % 2 == 1) Console.WriteLine("{0} It's odd ", n);
else Console.WriteLine("{0} For the even ", n);
Console.ReadKey()
; }
}
}2. seek “1-n” Between even numbers and / Odd and .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int sum0 = 0, sum1 = 0;
for(int i=1;i<=n;i++)
{
if (i % 2 == 1) sum0 += i;
else sum1 += i;
}
Console.WriteLine(" Odd and {0}, Even and {1}", sum0, sum1);
Console.ReadKey();
; }
}
}3. Determine how many uppercase characters there are , Lowercase letters , Numbers , Other characters .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
string s=Console.ReadLine();
int da = 0, xiao = 0, shuzi = 0, qita = 0;
for(int i=0;i<s.Length;i++)
{
if (s[i] >= 'A' && s[i] <= 'Z') da++;
else if (s[i] >= 'a' && s[i] <= 'z') xiao++;
else if (s[i] >= '0' && s[i] <= '9') shuzi++;
else qita++;
}
Console.WriteLine(" Capital {0} individual , Lowercase letters {1} individual , Numbers {2} individual , other {3} individual .", da, xiao, shuzi, qita);
Console.ReadKey();
; }
}
}4.90-100 good ,80-90 good ,60-80 pass , lower than 60 fail, .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
if (n >= 90 && n <= 100) Console.WriteLine(" good !");
else if (n >= 80 && n <= 90) Console.WriteLine(" good !");
else if (n >= 60 && n <= 80) Console.WriteLine(" pass !");
else Console.WriteLine(" fail, !");
Console.ReadKey();
; }
}
}5. Define two methods : An area used to find a circle , A method for finding the area of a rectangle .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
public static double solve(int x)
{
return Math.PI * x * x;
}
public static int fun(int x,int y)
{
return x * y;
}
public static void Main(string[] args)
{
int r = int.Parse(Console.ReadLine());
double sum = solve(r);
Console.WriteLine(" The area of the circle is {0}", sum);
int a= int.Parse(Console.ReadLine());
int b= int.Parse(Console.ReadLine()); ;
int ans = fun(a, b);
Console.WriteLine(" The area of the rectangle is {0}", ans);
Console.ReadKey();
; }
}
}6. Enter a string , See how many words there are ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
bool flag = false;
string s = Console.ReadLine();
int sum = 0;
for(int i=0;i<s.Length;i++)
{
if (s[i] != ' ')
{
if (flag == false)
{
sum++;
flag = true;
}
else if (s[i - 1] == ' ') sum++;
}
}
Console.WriteLine(sum);
Console.ReadKey();
; }
}
}7. Enter several grades , Output average score .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int sum = 0;
for(int i=1;i<=n;i++)
{
int x = int.Parse(Console.ReadLine());
sum += x;
}
Console.WriteLine(sum/n);
Console.ReadKey();
; }
}
}8. seek 1-n The number of completions in .( If a number is exactly equal to the sum of its factors , This number is called “ Complete ”)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int sum = 0;
for(int i=2;i<=n;i++)
{
int flag = 0;
for(int j=1;j<i;j++)
{
if (i % j == 0) flag += j;
}
if (flag == i) Console.WriteLine(i);// If he wants to output numbers , This is changed into sum++; That's it
}
//Console.WriteLine(sum);// There is no need to output the number
Console.ReadKey();
; }
}
}
9.a Can you divide b?( Exception handling mechanism ).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
try
{
int a = int.Parse(Console.ReadLine ());
int b = int.Parse(Console.ReadLine ());
if (a % b == 0) Console.WriteLine("YES");
else Console.WriteLine("NO");
}
catch
{
Console.WriteLine(" Input exception !");
}
Console.ReadKey();
; }
}
}10. Given an array , Find the subscript for the first occurrence of a number .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };
int n = int.Parse(Console.ReadLine());
int idx = -1;
for(int i=0;i<a.Length;i++)
{
if(a[i]==n)
{
idx = i;
break;
}
}
if (idx == -1) Console.WriteLine(" There is no such thing as ");
else Console.WriteLine(" Subscript to be :{0}",idx);
Console.ReadKey();
; }
}
}11. Judge whether a number is prime ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
bool flag = false;
for(int i=2;i<=n/i;i++)
{
if(n%i==0)
{
flag = true;
break;
}
}
if (flag == false&&n!=1) Console.WriteLine(" Prime number ");
else Console.WriteLine(" Not prime ");
Console.ReadKey();
; }
}
}12. Find the sum of an expression :1!+2!+3!+4!+...n!=?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int sum = 0;
int flag = 1;
int ans = 1;
while(flag<=n)
{
ans *= flag;
sum += ans;
flag++;
}
Console.WriteLine(sum);
Console.ReadKey();
; }
}
}13.( Bubble sort 163 Selection sort 171) Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vijurria
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[] { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
Array.Sort(a);
for (int i = 0; i < a.Length; i++)
Console.Write(a[i] + " ");
Console.ReadKey();
; }
}
}边栏推荐
- MySQL statement
- redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required
- Golang recursively encrypts and decrypts all files under the specified folder
- 程序员爆料:4年3次跳槽,薪资翻了3倍!网友:拳头硬了......
- js監聽用戶是否打開屏幕焦點
- [BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
- \Begin{algorithm} notes
- Leetcode 2190. 数组中紧跟 key 之后出现最频繁的数字(可以,一次过)
- The safety of link 01 was questioned, and "ultra high strength" became "high strength"_ Publicity_ Steel_ problem
- Structural requirement analysis of software engineering student information management system
猜你喜欢
随机推荐
mysql语句
[fishing artifact] UI library second change lowcode tool -- List part (I) design and Implementation
启牛开的证券账户安全吗?合法吗?
如何基于CCS_V11新建TMS320F28035的工程
pbootcms的if判断失效直接显示标签怎么回事?
MySQL statement
武汉大学甘菲课题组和南昌大学徐振江课题组联合招聘启事
CAS乐观锁
[research] reading English papers -- the welfare of researchers in English poor
How to do a good job of testing in the company (do a good job of testing)
CAS optimistic lock
Project training of Shandong University rendering engine system (VII)
uabntu的sudo
Project training of Shandong University rendering engine system (II)
[Hunan University] information sharing of the first and second postgraduate entrance examinations
STL -- function object
Learning notes of MySQL series by database and table
Iscc-2022 part WP
Large scale real-time quantile calculation -- a brief history of quantitative sketches
Probation period and overtime compensation -- knowledge before and after entering the factory labor law








