当前位置:网站首页>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 !
边栏推荐
- JS modularization
- Is it safe to open an account for online stock speculation? I'm a novice, please guide me
- [fluent] dart technique (independent main function entry | nullable type determination | default value setting)
- Why do I have a passion for process?
- Go cache of go cache series
- Review of the latest 2022 research on "deep learning methods for industrial defect detection"
- SBT tutorial
- Cs5268 perfectly replaces ag9321mcq typec multi in one docking station solution
- Google Earth Engine(GEE)——Landsat 9影像全波段影像下载(北京市为例)
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
猜你喜欢

7. Build native development environment

Talk about macromolecule coding theory and Lao Wang's fallacy from the perspective of evolution theory
![[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)](/img/80/215499c66243d5a4453d8e6206c012.jpg)
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)

After 65 days of closure and control of the epidemic, my home office experience sharing | community essay solicitation

【Hot100】21. Merge two ordered linked lists

How to realize the function of detecting browser type in Web System
![[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush](/img/e9/f316d02c3cad226055dcdec6781436.jpg)
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush

kernel tty_ struct

Summary of interview experience, escort your offer, full of knowledge points

Database schema notes - how to choose the right database in development + who invented relational database?
随机推荐
I want to ask you, where is a better place to open an account in Dongguan? Is it safe to open a mobile account?
Research Report on the overall scale, major manufacturers, major regions, products and applications of capacitive voltage transformers in the global market in 2022
Codeforces Round #771 (Div. 2)(A-C)
Send blessings on Lantern Festival | limited edition red envelope cover of audio and video is released!
Use graalvm native image to quickly expose jar code as a native shared library
Google Earth Engine(GEE)——Landsat 9影像全波段影像下载(北京市为例)
Go language learning summary (5) -- Summary of go learning notes
「 工业缺陷检测深度学习方法」最新2022研究综述
Interested parties add me for private chat
This team with billions of data access and open source dreams is waiting for you to join
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Adding data to the head or tail of the rar file can still decompress normally
Second hand housing data analysis and prediction system
When Valentine's Day falls on Monday
An analysis of the past and present life of the meta universe
sense of security
mysql
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of multi-channel signal conditioners in the global market in 2022
Want to ask, is there any discount for opening an account now? Is it safe to open an account online?
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip