当前位置:网站首页>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 :


边栏推荐
- (课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
- Walk into WPF's drawing Bing Dwen Dwen
- Basic operations of databases and tables ----- view data tables
- JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
- 基於Redis的分布式ID生成器
- Get the position of the nth occurrence of the string
- (五)R语言入门生物信息学——ORF和序列分析
- MySQL時間、時區、自動填充0的問題
- [Offer29] 排序的循环链表
- Flink late data processing (3)
猜你喜欢

ES6语法总结--上篇(基础篇)

【ESP32学习-1】Arduino ESP32开发环境搭建
![[Red Treasure Book Notes simplified version] Chapter 12 BOM](/img/ff/0ad410b5b556c0e16a4076a2a0577b.jpg)
[Red Treasure Book Notes simplified version] Chapter 12 BOM

ORA-02030: can only select from fixed tables/views

记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口

idea中好用的快捷键

程序设计大作业:教务管理系统(C语言)

單片機藍牙無線燒錄

The dolphin scheduler remotely executes shell scripts through the expect command

js 变量作用域和函数的学习笔记
随机推荐
Minio文件下载问题——inputstream:closed
JS数组常用方法的分类、理解和运用
map文件粗略分析
Basic operations of databases and tables ----- classification of data
About using @controller in gateway
Talking about the startup of Oracle Database
Servlet
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
單片機藍牙無線燒錄
Important methods of array and string
Detailed explanation of truncate usage
程序员老鸟都会搞错的问题 C语言基础 指针和数组
[Offer29] 排序的循环链表
.elf .map .list .hex文件
Amba, ahb, APB, Axi Understanding
Use of lists
Unity3D制作注册登录界面,并实现场景跳转
[offer29] sorted circular linked list
Types de variables JS et transformations de type communes
Unity场景跳转及退出