当前位置:网站首页>C simple question one
C simple question one
2022-07-07 23:34:00 【Bobo in summer】
1. Output in reverse order
string aa = Console.ReadLine();
string bb="";
for (int i = aa.Length-1; i >= 0; i--)
{
bb += aa[i];
}
Console.WriteLine(bb);
2. The length of three sides of a triangle is known a,b,c, The three sides are input by the user , Programming judgment a、b、c Whether the value of constitutes a triangle , If it forms a triangle , Then calculate and output the area of the triangle , Otherwise output “ Can't make a triangle ” Calculate the area of the triangle
double a =double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
double s = 0;
double area = 0;
if ((a + b > c) && (a + c > b) && (b + c > a))
{
Console.WriteLine(" Sure ");
s = 0.5 * (a + b + c);
area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
else
{
Console.WriteLine(" Can't form a triangle ");
}
3. Enter a string str1, Delete str1 All of them 0-9 The number character of , Output the processed string
string aa = Console.ReadLine();
string bb = "";
for (int i = 0; i < aa.Length; i++)
{
if (!char.IsDigit(aa[i]))
{
bb += aa[i];
}
}
Console.WriteLine(bb);
4. Input 10 Number , Calculate average , Count the number of data below the average and output the data below the average
Console.Write(" Please enter ten integers : Press enter Continue to enter ");
int[] a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
int b = 0;
for (int j = 0; j < 10; j++)
{
b += a[j];
}
float c = b / 10;
int count = 0;
for (int k = 0; k < 10; k++)
{
if (a[k] < c)
{
Console.Write("{0},", a[k]);
count++;
}
}
Console.WriteLine(" share {0} A number less than the average ", count);
5. Input 10 Number , Calculate average , Count the number of data higher than the average value and output the data higher than the average value
int[] srr = new int[10] {
1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
double sum = 0;
double ave = 0;
int count = 1;
for (int i = 0; i < 10; i++)
{
sum += srr[i];
count++;
}
ave = sum / count;
string aa = "";
int count1 = 1;
for (int j = 0; j < 10; j++)
{
if (srr[j] > ave)
{
aa += srr[j]+" ";
count1++;
}
}
Console.WriteLine("{0} ",aa);
Console.WriteLine(count1);
6. Enter some integers , Find the largest number , Secondary maximum , minimum value , Secondary minimum
int[] srr = new int[10];
for (int a = 0; a < 10; a++)
{
srr[a] =int.Parse( Console.ReadLine());
}
int temp = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 9-i; j++)
{
if (srr[j] > srr[j + 1])
{
temp = srr[j];
srr[j] = srr[j + 1];
srr[j + 1] = temp;
}
}
}
Console.WriteLine("{0},{1},{2},{3}",srr[9],srr[8],srr[0],srr[1]);
7. Enter several ordered positive integers , For the same data, only one , Output retained data . for example , The input data is : 2,2,2,3,3,4,5,5,6,6,8,8,9,9,9,10,10,10 The final output is : 2,3,4,5,6,8,9,10.
string str1=Console.ReadLine();;
string ret = "";
for (int i = 0; i < str1.Length; i++)
{
char ch = str1[i];
if (ret.IndexOf(ch.ToString()) >= 0)
{
continue;
}
ret = ret + ch.ToString();
}
Console.WriteLine(ret);
Console.ReadLine();
8. Enter a string , Judge if it's all numbers , Convert it to an integer , If other symbols are included , Give an error .
string aa=Console.ReadLine();
for (int i = 0; i < aa.Length; i++)
{
if (!char.IsDigit(aa[i]))
{
Console.WriteLine("error");
break;
}
else
Console.WriteLine(aa);
break;
}
9. Input 20 A positive integer , Count and output the number of odd and even numbers , And classify and output all odd and even numbers .
int[] arr = new int[10] {
1,2,3,4,5,6,7,8,9,10 };
string aa="";
string bb="";
int count1 = 1;
int count2 = 1;
for (int i = 0; i < 10; i++)
{
if (arr[i] % 2 == 0)
{
aa += arr[i]+" ";
count1++;
}
else
{
bb += arr[i]+" ";
count2++;
}
}
Console.WriteLine(aa);
Console.WriteLine(count1);
Console.WriteLine(bb);
Console.WriteLine(count2);
10. Input from terminal 5 Number , Output from small to large .
int[] a = new int[6];
Console.WriteLine(" Please enter six numbers :");
for (int l = 0; l < 6; l++)
{
a[l] = int.Parse(Console.ReadLine());
}
for (int j = 0; j < 6; j++)
{
for (int i = 0; i<5; i++)
{
int temp;
if (a[i] > a[i+1])
{
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
}
}
for (int k = 0; k < 6; k++)
{
Console.Write(" " + a[k]);
}
using System.Collections;
ArrayList list = new ArrayList();
for (int i = 0; i < 5; i++){
list.Add(int.Parse(Console.ReadLine()));
}
list.Sort();
for (int i = 0; i < list.Count; i++) {
Console.WriteLine(list[i]);
}
11. Read in... From the keyboard 20 Data into array , Count the number of negative numbers , And calculate the sum of these negative numbers .
int[] a = new int[20];
Console.WriteLine(" Please enter twenty numbers :");
for (int i = 0; i < 20; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
int count = 0;
double sum = 0;
for (int i = 0; i < 20; i++)
{
if (a[i] < 0)
{
count++;
sum += a[i];
}
}
Console.WriteLine(" Number :{0} Negative numbers and :{1}", count, sum);
12. seek n within ( barring n) Can't be 2 and 5 to be divisible by ( Can be 2 perhaps 5 Divisible but not divisible at the same time ) The square root of the sum of all natural numbers s,n Input from keyboard .
Console.WriteLine(" Please enter n");
int n = int.Parse(Console.ReadLine());
int sum = 0;
for(int i=0;i<n;i++)
{
if(i%2!=0&&i%5!=0)
{
sum += i;
}
}
double s = Math.Sqrt(sum);
Console.WriteLine(s);
random Generate 10 Number , Sort from small to large , Output max min , And the rest , Find the sum of the remaining numbers , Average .
public static void avee()
{
int[] srr = new int[10];
Random shuzu = new Random();
for (int i = 0; i < 10; i++)
{
srr[i]= shuzu.Next(60, 100);
}
//for (int i = 0; i < 10; i++)
//{
// srr[i] =int.Parse( Console.ReadLine());
//}
int m;
string ssss = "";
double ave;
double sum = 0;
for (int n = 0; n < 10; n++)
{
for (int j = 0; j < 9 - n; j++)
{
if (srr[j] > srr[j + 1])
{
m = srr[j];
srr[j] = srr[j + 1];
srr[j + 1] = m;
}
}
}
for(int i=1;i<srr.Length-1;i++)
{
ssss += srr[i]+" ";
sum += srr[i];
}
ave = sum / 8;
Console.WriteLine(" The maximum value is {0}", srr[9]);
Console.WriteLine(" The minimum value is {0}", srr[0]);
Console.WriteLine(" and :{0} Average {1}",sum,ave);
Console.WriteLine(ssss);
}
avee();
边栏推荐
- How to change the formula picture in the paper directly into the formula in word
- Live-Server使用
- Conversion between commonsmultipartfile and file
- Count the top 10 films at the box office and save them in another file
- IDEA 2021.3. X cracking
- Unity3d learning notes 5 - create sub mesh
- Unity3d learning notes 4 - create mesh advanced interface
- B_QuRT_User_Guide(40)
- SQL database execution problems
- Description of longitude and latitude PLT file format
猜你喜欢
B_ QuRT_ User_ Guide(38)
Puce à tension stabilisée LDO - schéma de bloc interne et paramètres de sélection du modèle
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
Map operation execution process
RE1 attack and defense world reverse
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
0-1背包问题
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
JS get the key and value of the object
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
随机推荐
Ros2 topic (03): the difference between ros1 and ros2 [02]
Installing spss25
B_ QuRT_ User_ Guide(36)
云原生数据仓库AnalyticDB MySQL版用户手册
【7.5】15. 三数之和
B_ QuRT_ User_ Guide(40)
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
Explain
B_ QuRT_ User_ Guide(37)
Design and implementation of spark offline development framework
StringUtils工具类
Extended tree (I) - graphic analysis and C language implementation
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
Cloud native data warehouse analyticdb MySQL user manual
LeeCode -- 6. Z 字形变换
ROS2专题(03):ROS1和ROS2的区别【02】
How to change the formula picture in the paper directly into the formula in word
Tree background data storage (using webmethod) [easy to understand]
POJ2392 SpaceElevator [DP]
2021icpc Shanghai h.life is a game Kruskal reconstruction tree