当前位置:网站首页>Spend more time with your computer on this special holiday, HHH
Spend more time with your computer on this special holiday, HHH
2022-07-02 21:01:00 【*Yiiiiiiiiiiiiii】
Input number n , Print out from... In order 1 To the biggest n A decimal number . Such as input 3 , Then print out 1、2、3 Up to the biggest 3 digit 999 .
- Instead of printing, return a list of integers
- n As a positive integer
OJ link 【 Question no. of niuke.com : JZ17 Print from 1 To the biggest n digit 】
Example :
Input :1
Return value :[1,2,3,4,5,6,7,8,9]
int* printNumbers(int n, int* returnSize )
{
}
If there is no interface provided by the above input , We don't need to apply for space dynamically !
First of all, be clear n The largest number of digits , It's actually 10^n - 1
1 digit : 10^1 - 1
2 digit : 10^2 - 1
3 digit : 10^3 - 1
...( call pow function :pow(10,n)-1)
The actual code is as follows :
#include<stdio.h>
#include<math.h>
int main()
{
int n,i=0;
scanf("%d",&n);
for(i=1;i<=(pow(10,n)-1);i++)
{
if(i==(pow(10,n)-1))
{
printf("%d",i);
}
else
printf("%d,",i);
}
return 0;
}
Operation of the :
Because this code is relatively simple , So I won't describe it in detail here .
premium : According to the interface provided by Niuke online , Implement this interface to complete the requirements of the topic
After this is clear, the dynamic application space , Just fill in the value , It should be noted that the array subscript is from 0 Start , And the value from 1 Start
int* printNumbers(int n, int* returnSize )
{
*returnSize = pow(10, n) - 1; // Determine the maximum number
int *arr = (int *)malloc(sizeof(int)*(*returnSize));// Apply for space of sufficient size
for (int i = 0; i < *returnSize; i++)
{
arr[i] = i+1;// Subscript from 0 Start , And the value from 1 Start
}
return arr;
}
1946 year 2 month 14 Japan , The world's first general-purpose computer was born at the University of Pennsylvania , Please spend more time with your computer on this special holiday , Ha ha ha ha ha ha ha !
边栏推荐
- 笔记本安装TIA博途V17后出现蓝屏的解决办法
- Is it safe to open an account for online stock speculation? I'm a novice, please guide me
- Cs5268 perfectly replaces ag9321mcq typec multi in one docking station solution
- 「 工业缺陷检测深度学习方法」最新2022研究综述
- I did a craniotomy experiment: talk about macromolecule coding theory and Lao Wang's fallacy from corpus callosum and frontal leukotomy
- Internal/validators js:124 throw new ERR_ INVALID_ ARG_ Type (name, 'string', value) -- solution
- Welfare | Pu Aries | liv heart co branded Plush surrounding new products are on the market!
- Basic concept of database, installation and configuration of database, basic use of MySQL, operation of database in the project
- Analyze comp-206 advanced UNIX utils
- Send blessings on Lantern Festival | limited edition red envelope cover of audio and video is released!
猜你喜欢
26 FPS video super-resolution model DAP! Output 720p Video Online
How to do interface testing? After reading this article, it will be clear
Friends who firmly believe that human memory is stored in macromolecular substances, please take a look
Customized Huawei hg8546m restores Huawei's original interface
【871. 最低加油次数】
[question brushing diary] classic questions of dynamic planning
Activation function - relu vs sigmoid
Why do I have a passion for process?
Write the content into the picture with type or echo and view it with WinHex
After 65 days of closure and control of the epidemic, my home office experience sharing | community essay solicitation
随机推荐
Research Report on the overall scale, major manufacturers, major regions, products and applications of micro hydraulic cylinders in the global market in 2022
In depth understanding of modern web browsers (I)
通信人的经典语录,第一条就扎心了……
股票开户要找谁?手机开户是安全么?
[internship] solve the problem of too long request parameters
Longest public prefix of leetcode
The first of the classic quotations of correspondents is heartbreaking
Research Report on the overall scale, major manufacturers, major regions, products and applications of outdoor vacuum circuit breakers in the global market in 2022
5 environment construction spark on yarn
Summary of interview experience, escort your offer, full of knowledge points
ROS learning (10): ROS records multiple topic scripts
qwb2018_ core kernel_ rop
How can testers do without missing tests? Seven o'clock is enough
pytorch 模型保存的完整例子+pytorch 模型保存只保存可训练参数吗?是(+解决方案)
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
Research Report on the overall scale, major manufacturers, major regions, products and applications of battery control units in the global market in 2022
Who do you want to open a stock account? Is it safe to open a mobile account?
JDBC | Chapter 4: transaction commit and rollback
「 工业缺陷检测深度学习方法」最新2022研究综述
kernel_ uaf