当前位置:网站首页>Reverse output three digit and arithmetic sequence
Reverse output three digit and arithmetic sequence
2022-07-07 23:39:00 【Yuesi】
Markdown Answer key
Count garlic customers to output three digits in reverse :
Original link
Calculate the last term of the garlic guest equal difference series :
Original link
subject
Garlic has a three digit number , She wants you to output the three digits in reverse .
Input format
A three digit number n
Output format
Reverse output n, To keep the leading 0.
Extra space at the end of each line when outputting , It doesn't affect the correctness of the answer
Data range
100≤n≤999
The sample input
100
Sample output
001
The question
Read in a three digit integer , Output it from right to left
Ideas
- 1. The integer n Read in as a whole , Create three integer variables to represent their bits, tens and hundreds , Output in the order of one bit, ten bits and hundreds
- 2. The integer n Divide by digits 3 Integers are read in sequence and stored in three integer variables , Output in the reverse order of read in storage
- 3. take n Read in as a whole ( example : hypothesis n by 123), establish 3 Variables are stored in turn n A bit of (a=3) ten (b=2) Hundred bit (c=1), And take the bits as the required output ( And n It's reverse , Such as 100 And 001) Top 100 , Ten as ten , Hundreds as a bit ( example : With n=123 For example Output number =3100+210+1*1=321 )
Pay attention to whether there is 0!!!- 4. The capacity of the created array is greater than or equal to 3, From the subscript for 0 Start storing into the array , And subscript from 2 Start to 0 Traverse the array and output the corresponding value ( available for loop )
Pit point
- 1. When the number of reverse output Output as a whole When , Pay attention to whether there is 0, Such as n=100 The reverse output is not 001 It is 1.( The output is not 3 digit )
Solution
Output to form three digits
scanf("%03d", Variable name ); ( This variable represents the relation with n Inverse integer )
Code
Will work with n The reverse number is output three times according to the number of digits
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int a1,a2,a3;
a1=n%10;
//a1=n%100 It's OK ; Single digit
a2=n/10%10;
// Ten digits
//405 except 10 be equal to 40 more than 5 405/10=40 40 except 10 be equal to 4 more than 0
//40%10=0
a3=n/100;
// Hundreds of digits example 405 except 100 be equal to 4 more than 5
// 405/100=4 405%100=5
printf("%d%d%d",a1,a2,a3);
return 0;
}
Will work with n The reverse number is output as an integer at one time
#include<stdio.h>
int main(){
int n;
int gewei,shiwei,baiwei;
int sum=0;// The assignment is 0 Don't miss
scanf("%d",&n);
gewei=n%10;//gewei=n%100; It's OK
shiwei=n/10%10;
baiwei=n/100;
sum=gewei*100+shiwei*10+baiwei;
// And n reverse , But not necessarily in three digits
printf("%03d",sum);
return 0;
}
summary
1. Cultivate the good habit of looking at the range of input and output data
2. Give full consideration to special circumstances
…
subject
The arithmetic sequence is a very interesting sequence , The difference between any two adjacent terms of it is equal .
Garlic gentleman gives the first two terms of an arithmetic sequence a1,a2, Please n What is the item? .
Input format
a line , Contains three integers a1, a2, n.
Output format
An integer , That is to say n Item value .
Data range
-100 ≤ a1, a2 ≤ 100, 0<n≤1000.
The sample input
1 4 100
Sample output
298
The question
The first term and the second term of the known arithmetic sequence are known , Output No n term
Ideas
- 1. Find the tolerance of the arithmetic sequence d, utilize an=a1+(n-1)*d Formula evaluation
- 2. Use the relationships of the series to evaluate ,ak+as=aj+al;( Conditions k+s=j+l)
- 3. according to n Range build array ( The capacity is greater than 1000, You can also wait , But not recommended ), Find the value of each term
Output the value of the corresponding subscript in the array as required
Pit point
- 1.an The expression formula of must be remembered , Otherwise, we can only find the value by pushing the law
Code
#include<stdio.h>
int main(){
int a1=0,a2=0,n=0;// The first one is , The second item , And the number of bits to output
int d;// Save tolerance d Equal to the last term of the sequence minus the previous term d=a2-a1=a3-a2=a4-a3......=an-an-1
scanf("%d",&a1);
scanf("%d%d",&a2,&n);
d=a2-a1;
printf("%d\n",a1+(n-1)*d);
//an=a1+(n-1)*d;
// an It's the... Of the arithmetic sequence n term
//a1 It's the first one d Is the tolerance equal to the last item of the sequence minus the previous item
return 0;
}
summary
The formula of accumulating the sequence of equal differences ,an=a1+(n-1)*d
When d If you don't know, you can subtract any two terms to get
Such as :ak-as=(k-s)*d;
边栏推荐
- USB (XVIII) 2022-04-17
- Fibonacci number of dynamic programming
- Given an array, such as [7864, 284, 347, 7732, 8498], now you need to splice the numbers in the array to return the "largest possible number."
- Three questions TDM
- Extract the file name under the folder under win
- 【汇总】看过的一些Panel与视频
- PCB wiring rules of PCI Express interface
- List. How to achieve ascending and descending sort() 2020.8.6
- IDEA 2021.3. X cracking
- How to login and enable synchronization function in Google browser
猜你喜欢
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
SAP HR family member information
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
进度播报|广州地铁七号线全线29台盾构机全部完成始发
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
Open source hardware small project: anxinco esp-c3f control ws2812
Spark 离线开发框架设计与实现
UE4_ Ue5 combined with Logitech handle (F710) use record
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
Take you hand in hand to build feign with idea
随机推荐
SAP HR奖罚信息导出
Take you hand in hand to build Eureka server with idea
Anti climbing means cracking the second
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
Extract the file name under the folder under win
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
C cat and dog
【汇总】看过的一些Panel与视频
Access database query all tables SQL
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
Fibonacci number of dynamic programming
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
Installing gradle
Markdown
MongoDB快速入门
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
USB (XVII) 2022-04-15
Deep understanding of MySQL lock and transaction isolation level
【实验分享】通过Console口登录到Cisco设备
SAP memory parameter tuning process