当前位置:网站首页>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();
边栏推荐
- 2022第六季完美童模陕西总决赛圆满落幕
- Mysql索引优化实战二
- [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
- Archlinux install MySQL
- Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
- Caip2021 preliminary VP
- Coreseek:第二步建索引及測试
- 欢聚时代一面
- [untitled]
- 给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
猜你喜欢

B_ QuRT_ User_ Guide(37)

SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration

Vulnerability recurrence ----- 49. Apache airflow authentication bypass (cve-2020-17526)

UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)

Unity3d Learning Notes 6 - GPU instantiation (1)

城联优品作为新力量初注入,相关上市公司股价应声上涨150%

What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method

The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way

Cloud native is devouring everything. How should developers deal with it?

USB (XV) 2022-04-14
随机推荐
0-1背包问题
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
Add data analysis tools in Excel
One week learning summary of STL Standard Template Library
leetcode-520. Detect capital letters -js
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
LeeCode -- 6. Zigzag transformation
LeeCode -- 6. Z 字形变换
Open source hardware small project: anxinco esp-c3f control ws2812
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
Explain
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
Turbo introder common scripts
Anxin vb01 offline voice module access intelligent curtain guidance
LDO voltage stabilizing chip - internal block diagram and selection parameters
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
城联优品作为新力量初注入,相关上市公司股价应声上涨150%
MATLAB signal processing [Q & A essays · 2]
SAP HR 社会工作经历 0023