#include <stdio.h>
#include <string.h>
/*
逆序输出字符/数字
思路一:使用数组逆序打印结果
思路二:使用数字拆分法
思路三:根据输出特点可以发现是先进后出的特点,可以使用栈
*/
int main()
{
// 使用数组逆序输出字符串(适用负数,小数,字符)
char c[100];
scanf("%s", c);
for (int i = strlen(c) - 1; i >= 0; i--)
{
printf("%c", c[i]);
}
return 0;
// 使用数组逆序输出数字
// 对于正数,如果是 ““负数”” 也要使用数组方法,可以参考上面的方法,转成字符窜处理
int a[100];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (int i = n - 1; i >= 0; i--)
{
printf("%d ", a[i]);
}
// 使用数字拆分法逆序输出正数
int x, sum = 0;
scanf("%d", &x);
while (x)
{
sum = sum * 10 + x % 10;
x /= 10;
}
printf("%d", sum);
// 使用数字拆分法逆序输出负数
int x1, sum1 = 0, temp;
scanf("%d", &x1);
// 把负数转成正数
// 处理方法1(推荐)
temp = -x1;
// 处理方法2
// temp = x1 + 2 * (-x1);
while (temp)
{
sum1 = sum1 * 10 + temp % 10;
temp /= 10;
}
printf("-%d", sum1);
}
相关推荐
C语言字符逆序
写在前面:这里是小王成长日志,一名在校大学生,想在学习之余将自己的学习笔记分享出来,记录自己的成长轨迹,帮助可能需要的人。欢迎关注与留言。 题目: 题目链接:https://www.dotcpp.com/oj/problem1093.html 题目 1093: 字符逆序 时间限制: 1Sec 内存限制: 64MB 提交: 14369 解决: 7346 题目描述 将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 输入 输入包括一行。 第一行输入的字符串。 输出 输出转换好的逆序字.
c语言 字符串的系列操作(字符串的逆序输出、字符串类型与int、double的互相转换)
1.字符串的逆序输出 c语言把字符串逆转看起来是一件非常简单的事情,就如同把数组逆序一样,本质上字符串就是一个char类型的数组,但是其中有不少的细节值得注意。 #include<stdio.h> #include<string.h> //参数char *str 不用const void reverse(char *str){//不同于数组,不需要传递长度 size_t len = strlen(str);//长度 size_t...
C语言——逆序输出整数和正序分解正整数
一、逆序输出正整数 二、用函数逆序输出整数 三、 正序分解正整数 四、总结
学习c语言的第一天
学习c语言准备复试上机的第一天。 为了适应考试环境,题目集源于PTA 平台,代码均是在PTA平台上练习的。 1.厘米换算英尺英寸 如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(foot+inch/12)×0.3048。现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12英寸。 代码如下 #include <stdio.h> int main() { int CM; scanf("%d",&CM); .
【C语言】-- 将一个数组逆序输出
将一个数组逆序输出。第一种方法:直接从最后一个元素进行输出即可,倒着输出。第二种方法:将数组的第一个元素与最后一个元素交换,依次类推,然后正顺序输出。
C语言基础-数组逆序输出
题目描述 输入一个数组的长度并输入数组中的内容,将数组中的内容逆序打印出来 输入 第一行为数组长度 第二行为数组中的内容 输出 输出一行,逆序打印数组内容 样例输入 5 1 2 3 4 5 样例输出 5 4 3 2 1 代码实现 #include "stdio.h" int main(){ int arr[100]; int num; printf("请输入数组长度:"); scanf("%d",&num); printf("请输入数组:"); for(int i=0;i<
c语言各类问题 代码
定义一个结构体,有两个成员变量,一个整型的n,一个字符型的c,利用结构体类型声明一个具有5个元素的数组,并随机初始化,根据成员变量n进行从小到大排序,然后输出 冒泡排序然后 在输出结构体#includestruct d{int x;char y;};int main(void){struct d a[5];int i,d;int b[6]; for(i=0;i{scanf("%d%c",&a[i]
【C语言】将一个数组逆序输出
程序分析 用第一个与最后一个交换。 源代码 #include<stdio.h> #include<stdlib.h> #define N 5 int main() { int a[N] = { 1, 2, 3, 4, 5 }; printf("原始数列为:"); for (int i = 0; i < N; i++) { printf("%d ", a[...
c语言100道题,100道经典c语言题.doc
100道经典c语言题1.输入两个正整数,m和n,求其最大公约数和最小公倍数。#includevoid main(){ int hcf(int,int); /*函数声明*/ int lcd(int,int,int); /*函数声明*/ int u,v,h,l; printf("Please input two numbers:\n"); scanf("%d,%d",&u,&v); h...
视频倍速 - 在线调倍速的加速器APP工具
一刀工具箱APP提供一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!视频倍速-在线调倍速的加速器-一刀工具箱APP。...
Unity新手必看:5分钟搞定TextMeshPro中文乱码,告别小方块(附7000+常用字库)
本文详细介绍了Unity中TextMeshPro中文乱码问题的解决方案,包括快速生成中文字体的步骤和优化技巧。通过使用支持中文的.ttf字体文件和自定义字符集,开发者可以在5分钟内解决TMP显示小方块的问题,提升游戏或应用的文本显示效果。
C语言基础练习:字符串逆序与素数判定实战
C语言作为系统编程的基石,其指针操作和内存管理能力是程序员的核心竞争力。通过字符串逆序实现可以深入理解数组与指针的底层关系,而素数判定算法则体现了数学思维与计算优化的结合。在嵌入式开发和高性能计算领域,这类基础问题的优化方案直接影响系统效率。本文以GCC编译环境为例,演示了如何通过异或运算实现无临时变量交换,以及利用平方根优化将素数判定复杂度从O(n)降至O(√n)。这些技术不仅适用于面试场景,更是物联网设备开发和算法引擎实现中的常见需求,特别适合需要精确控制内存的嵌入式系统和实时系统开发。
MediaCodec视频解码流程详解及参考demo
本文主要讲解mediacodec的视频解码流程,及demo参考例子。
C语言指针实现逆序输出数组元素
C语言指针实现逆序输出数组元素 C语言指针实现逆序输出数组元素 实验平台:codeBlocks #include <stdio.h> #include <stdlib.h> //逆序输出函数 void swap(int *p, int m); int main() { int a[10], i; int *pa; //指针赋值 pa=a; //逐个输入 for(i=0 ; i<10; i++)
APB Timer验证环境搭建——学习笔记(1)
以下为个人学习笔记,如有疏漏,请大家指正补充~~APB Timer是一个简单的下行计数器,包括一个32位计数器和一组比较器,可以实现多种计时功能。包括生成一次性中断或者定时中断。
Access查询中的Dlookup函数的妙用
在Microsoft Access中,处理和分析数据的过程中,常常会遇到需要根据条件从其他记录中提取特定数据的情况。这时候,Dlookup函数就成了开发者和数据分析师的得力助手。今天我们将通过一个具体的实例,详细探讨如何利用Dlookup函数来解决复杂的查询问题。
C语言 逆序输出 解法集合
C语言 数组练习 逆序输出 常见解法集合 问题:将给定的n个整数存入数组后,再按逆序输出数组中的元素,输出时相邻数字中间用一个空格分开,行末不得有多余空格。 解法一: #include <stdio.h> #define MAXN 10 int main() { int i, first, n; int num[MAXN]; scanf("%d", &...
SPAD IMX479规格_VOP
对于VOP的定义,很多人可能是不理解这一路的供电,实际上这一路供电是非常重要的,这是给器件SPAD供电,决定SPAD是否work,在大部分的paper以及大部分公司,基本都是叫VOP,名称是SPAD breakdown voltage power supply,严格意义上叫Operating Voltage,工作电压。当然有些公司也有一些其他叫法就不提了。其实大家可以明显的看出,典型值-20.5没有发生变化,市面上绝大多数VOP的典型值也都是在-20V这边。
C语言单向链表的逆序输出
最近在学习链表,看到书上说可以采取每次在链表头部插入新增节点的方法,将链表逆序,也就是建立的链表节点内容与数据的输入顺序相反。我便来了兴趣,想着试试看,结果没搞懂,于是开始百度。看了几遍博客后终于是明白了,而后写作的兴趣又上来了。。。。一个初学者就算再怎么来了兴趣,也不可能写得很好,所以有不对的地方,欢迎大家指出!顺便这里附上一篇写得很好的博客:点击蓝色字体。我正是看了这篇博客才大概弄懂了链表逆序,还自己手画链表才理解的。 博主要讲的单链表逆序...
Linux下搭建简易的HTTP服务器完成图片显示
篇文章作为Linux下socket(TCP)网络编程的练习,使用C语言代码搭建一个简单的HTTP服务器,完成与浏览器之间的交互,最终在浏览器上显示一张图片;通过这个例子可以巩固socket里多线程使用,也可以方便学习了解HTTP协议。
【unity游戏开发入门到精通——UGUI】UI控件 —— Image图像控件
【unity游戏开发入门到精通——UGUI】UI控件 —— Image图像控件
c语言整数逆序输出
c语言的逆序输出 第一种: 这种方法的思想是输入的x对10求余,比如123对10求余得3,然后123再除以10的12,逆序时3乘以10,下一轮12对10求余得2, 然后12除以10得1,下一步得到30+2,以此类推; 但是这种方法遇到1000,或者200000等除首位外都是零的数逆序不符合 第二种方法: 求余后直接输出; 结果显示 ...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
C 数组逆序输出
编写程序对固定内容的数组进行逆序输出,第一个值和最后一个值的位置互换。 效果 完整代码 #include<stdio.h> #define N 10 int main() { int a[N]={10,100,20,43,54,15,6,77,82,91}; int i,t; printf("原始数组是:\n"); for(i=0;i<N;i++...
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
Probability and Statistics - 4th edition
Probability and Statistics - 4th edition
C语言学习,逆序输出
逆序输出(数组) 如,输入五个数,逆序输出 #include<stdio.h>//逆序输出 int main(){ int i=0; int a[5];//定义五个数的数组 int t=0;//三角交换中间变量 printf("输入5个数\n"); for(i=0;i<5;i++){ scanf("%d",&a[i]);//数据存入数组a } prin...
霍尼韦尔SoftMaster使用说明
霍尼韦尔SoftMaster使用说明
C语言:逆序输出整数数组。
问题 定义函数将一维数组逆序(对应位置数据交换)。 主函数中输入10个整数,然后调用函数将其逆序并输出逆序后的结果。 输入提示:“input 10 numbers:” 输入格式:"%d" 输出格式:"%5d" #include <stdio.h> void reverse(int a[],int n) { int i, j, t; for (i = 0, j = n-...
C语言练习——逆序输出数字
这篇博客介绍了如何使用C语言来完成逆序数字的输出。
8926



被折叠的 条评论
为什么被折叠?



