当前位置:网站首页>C programming exercise
C programming exercise
2022-07-06 12:30:00 【Bald eleven】
Write the code as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1
{
class Program
{
static void Main(string[] args)
{
int k1 = 364;
int k2 = 364;
while (k1>=3)
{
k2+= k1 / 3;
k1 = (k1 / 3) + (k1 % 3);
}
Console.WriteLine(" You can drink it altogether {0} A bottle of coke , be left over {1} Empty bottles ", k2, k1);
Console.ReadKey(true);
}
}
}
The program runs as follows :
Write the code as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Please enter the string :");
string str = Console.ReadLine();
// Convert a string to an array of characters
char[] strArray = str.ToArray();
// Loop traversal
for (int i = 0; i < strArray.Length; i++)
{
// Decide if it's a letter
if ((strArray[i] >= 'A' && strArray[i] <= 'Z') || (strArray[i] >= 'a' && strArray[i] <= 'z'))
{
strArray[i] = (char)(strArray[i] + 3);
// Lowercase letters
if (strArray[i] > 'z' && strArray[i] < 'z' + 4)
{
strArray[i] = (char)(strArray[i] - 26);//26 Is a total period
}
// Capital
if (strArray[i] > 'Z' && strArray[i] < 'Z' + 4)
{
strArray[i] = (char)(strArray[i] - 26);
}
}
}
foreach ( char temp in strArray )
{
Console.Write(temp);
}
Console.ReadKey(true);
}
}
}
The program runs as follows :
Write the code as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1
{
class Program
{
static void Main(string[] args)
{
// The user enters an ordered array
string str = Console.ReadLine();// Get user input Separate... With spaces
string[] strArray = str.Split(' ');
int[] intArray = new int[strArray.Length];// Define that the length of the number array is equal to that of the character array
for (int i = 0; i < strArray.Length; i++) // Get an array of numbers
{
int number = Convert.ToInt32(strArray[i]);
intArray[i] = number;
}
for(int j=0;j<intArray .Length -1;j++)// How many numbers, how many rounds ( length -1 Round is also ok , Because there are only numbers left in the end , There is no need to compare )
{
// Compare
for(int i=0;i<intArray .Length -1;i++)// Compare and sort each number in the array
{
if(intArray [i]>intArray [i+1])
{
int temp = intArray[i];
intArray[i] = intArray[i +1];
intArray[i + 1] = temp;
}
}
}
foreach (int temp in intArray )
{
Console.Write(temp + " ");
}
Console.ReadKey(true);
}
}
}
The program runs as follows :
Write the code as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();// Get user input Separate... With spaces
string[] strArray= str.Split(' ');
int[] intArray = new int[strArray.Length];// Define that the length of the number array is equal to that of the character array
// Get an array of numbers
for (int i=0;i<strArray .Length;i++)
{
int number= Convert.ToInt32(strArray [i]);
intArray[i] = number;
}
int min=intArray [0];
int minIndex = 0;
for (int i=1;i<intArray .Length;i++)
{
if (intArray [i]<min)
{
min = intArray[i];
minIndex = i;
}
}
int t;
t = intArray[0];
intArray[0] = intArray[minIndex];
intArray[minIndex] = t;
foreach (int tep in intArray )
{
Console.Write(tep );
}
Console.ReadKey(true);
}
}
}
The program runs as follows :
Write the code as follows :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1
{
class Program
{
static void Main(string[] args)
{
// Judge whether it is a legal identifier It consists of English letters and underscores Cannot start with a number
string str = Console.ReadLine();
bool pd = true;
for(int i=0;i<str.Length;i++)
{
if ((str[i] < 'a' || str[i] > 'z') && (str[i] < 'A' || str[i] > 'Z') && (str[i] < '0' || str[i] > '9') && str[i] != '_')// Lowercase letters Capital Numbers Underline
{
pd = false;
break;
}
}
if(str[0]>='0'&&str[0]<='9')
{
pd = false;
}
if (pd )
Console.WriteLine(" yes ");
else
Console.WriteLine(" No ");
Console.ReadKey(true);
}
}
}
The program runs as follows :
边栏推荐
- Minio file download problem - inputstream:closed
- Use of lists
- NRF24L01故障排查
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- Symbolic representation of functions in deep learning papers
- dosbox第一次使用
- Kconfig Kbuild
- Servlet
- 基于Redis的分布式ID生成器
- AMBA、AHB、APB、AXI的理解
猜你喜欢
ES6 grammar summary -- Part I (basic)
Classification, understanding and application of common methods of JS array
Arm pc=pc+8 is the most understandable explanation
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
ES6语法总结--下篇(进阶篇 ES6~ES11)
VSCode基础配置
Learning notes of JS variable scope and function
基于Redis的分布式ID生成器
CUDA C programming authoritative guide Grossman Chapter 4 global memory
随机推荐
Unity3D制作注册登录界面,并实现场景跳转
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
Redis based distributed locks and ultra detailed improvement ideas
嵌入式启动流程
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
1081 rational sum (20 points) points add up to total points
[leetcode19] delete the penultimate node in the linked list
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
[Red Treasure Book Notes simplified version] Chapter 12 BOM
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
SSD technical features
Kconfig Kbuild
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
Arduino get random number
(四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图
Pat 1097 duplication on a linked list (25 points)
AMBA、AHB、APB、AXI的理解
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
ARM PC=PC+8 最便于理解的阐述