当前位置:网站首页>1165: decimal part of real number (pointer)
1165: decimal part of real number (pointer)
2022-04-21 09:10:00 【Qian Qian】
1165: The fractional part of a real number ( Pointer theme )
Title Description
Read in a real number , Output the decimal part of the real number , If the decimal part is redundant, the end 0, Please remove . Such as the input 111111.12345678912345678900
The output 0.123456789123456789. If you remove the end 0 After that, the decimal part is 0, The output “No decimal part”. Note that the number of digits of the real number does not exceed 100 position .
Please define and use the following functions .
char *decimal(char *p)
{
The string p The decimal part from the decimal point of the real number represented by is stored in a string , And the function returns , if p by “123.456”, The returned string is “.456”. If the decimal part is 0, Return null pointer NULL.
}
Input
Enter a real number . No more than 100 position .
Output
Output decimal part , Output takes up one line .
The sample input Copy
111111.12345678900012345678900
Sample output Copy
0.123456789000123456789
source / classification
#include<stdio.h>
#include<string.h>
#define N 102
char *decimal(char *p){
char *q;
int k=0;
q=(char *)malloc(sizeof(char)*N);
for(int i=0;p[i]!='\0';i++){
if(p[i]=='.'){
for(int j=i;p[j]!='\0';j++){
q[k++]=p[j];
}
q[k]='\0';//'\0' Control character for the end of output
break;
}
}
k--;
// Get some extra 0
while(q[k]=='0'){
q[k]='\0';
k--;
}
if(q[k]=='.') return NULL;
return q;
}
int main(){
char *p;
p=(char *)malloc(sizeof(char)*N);
gets(p);
if(decimal(p)==NULL) printf("No decimal part\n");
else printf("0%s\n",decimal(p));
return 0;
}
版权声明
本文为[Qian Qian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210906131838.html
边栏推荐
- 笔记0104. MySQL 高级 - 索引 - 概述
- 2022 Shandong Province safety officer C certificate examination questions and simulation examination
- 1157: 连续的n个1
- Postman test excel file import and export function
- Redisson简介和整合
- Redisson introduction and integration
- 年金险安全靠谱吗?收益是多少啊?
- YApi基本使用(2022-04-15)
- Convolution operation and cross correlation operation
- Buuctf [geek challenge 2019] havefun
猜你喜欢

LDO系列--PSRR

Simulated 100 questions and simulated examination of Shanghai safety officer C certificate examination in 2022

Postman test excel file import and export function
Implementation of pure student information linked list system in C Have you learned

CC00026.CloudJenkins—————————————

PageRank case Airport

Flink的api入门案例

Penetration test - get the system fofa keyword to brush the hole

2022年主要的编程语言及应用
![BUUCTF[HCTF 2018]WarmUp](/img/89/5d7d147dfb8e2bc10a2ff0bb68debe.png)
BUUCTF[HCTF 2018]WarmUp
随机推荐
1152: 二分搜索
Flink's API introduction case
Convolution operation and cross correlation operation
Surfaceview high performance rendering (IV) code practice - drawing multiple pictures
编程如何提高自己的水平能力?学编程最重要的是什么?请看凡人浅谈如何学C
Maya basic tutorial and basic operation explanation
Handler asynchronous message passing mechanism (I) common basic usage of handler
Error in idea connection to sqlserver
CC00043. CloudJenkins—————————————
Postman test excel file import and export function
1147: 查找子数组
CC00026. CloudJenkins—————————————
1168: 账单(指针专题)
Template adaptation guide for toudabi thesis
ARPU, the user of China Mobile, has re entered the rising channel, and the salary of employees has also increased steadily
Worker man passes parameters to the method in timer
How to improve the ability of programming? What is the most important thing about learning programming? Please see how mortals learn C
规划自己的健康问题
1149: 组合三位数之二
Major programming languages and applications in 2022