当前位置:网站首页>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 !
边栏推荐
- [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)
- Resunet tensorrt8.2 speed and video memory record table on Jetson Xavier NX (continuously supplemented later)
- Activation function - relu vs sigmoid
- Research Report on the overall scale, major manufacturers, major regions, products and applications of micro hydraulic cylinders in the global market in 2022
- Sword finger offer (I) -- handwriting singleton mode
- [fluent] dart technique (independent main function entry | nullable type determination | default value setting)
- Redis -- three special data types
- Research Report on the overall scale, major manufacturers, major regions, products and applications of hollow porcelain insulators in the global market in 2022
- Properties of expectation and variance
- Attack and defense world PWN question: Echo
猜你喜欢
SBT tutorial
[real case] trap of program design - beware of large data
[QT] QPushButton creation
Exemple complet d'enregistrement du modèle pytoch + enregistrement du modèle pytoch seuls les paramètres d'entraînement sont - ils enregistrés? Oui (+ Solution)
5 environment construction spark on yarn
Go language learning summary (5) -- Summary of go learning notes
B-end e-commerce - reverse order process
Internal/validators js:124 throw new ERR_ INVALID_ ARG_ Type (name, 'string', value) -- solution
I drew a Gu ailing with characters!
Write the content into the picture with type or echo and view it with WinHex
随机推荐
How my mother-in-law and daughter-in-law get along
想请教一下,究竟有哪些劵商推荐?手机开户是安全么?
Second hand housing data analysis and prediction system
26 FPS video super-resolution model DAP! Output 720p Video Online
burp 安装 license key not recognized
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
Research Report on the overall scale, major manufacturers, major regions, products and applications of metal oxide arresters in the global market in 2022
Implementing yolox from scratch: dataset class
[kubernetes series] comparison of space and memory usage before and after kubedm reset initialization
Is it safe to open an account for online stock speculation? I'm a novice, please guide me
[QT] QPushButton creation
Codeworks global round 19 (CF 1637) a ~ e problem solution
kernel_ uaf
Research and Analysis on the current situation of China's clamping device market and forecast report on its development prospect
数据库模式笔记 --- 如何在开发中选择合适的数据库+关系型数据库是谁发明的?
Jetson XAVIER NX上ResUnet-TensorRT8.2速度與顯存記錄錶(後續不斷補充)
Interested parties add me for private chat
API documentation tool knife4j usage details
Research Report on the overall scale, major manufacturers, major regions, products and applications of battery control units in the global market in 2022
【Kubernetes系列】kubeadm reset初始化前后空间、内存使用情况对比