当前位置:网站首页>Freshman C language summary post (hold change) Part1 output diamond
Freshman C language summary post (hold change) Part1 output diamond
2022-06-23 01:43:00 【Mr_ Always】
This series is a freshman C Language Xiaobai's last semester programming assignment , At the end of a semester, I'd like to make a simple arrangement . In the content part, there is the article of the great God , Some code snippets are also a bit troublesome , For the purpose of sharing and summarizing , You are welcome to correct the shortcomings !!!
【 Problem description 】 Give a number n ,2 <= n <= 9, Output diamond
【 Input form 】 A number
【 Output form 】 A diamond
【 The sample input 】4
【 Sample output 】
1
2 2
3 3 3
4 4 4 4
3 3 3
2 2
1
first line :3 After spaces , Output 1, And then go back ; Note that there are no extra spaces at the end
The second line :2 After spaces , Output 2, One more space , Then the output 2, And then go back ;
The third line :1 After spaces , Output 3 individual 3, There is a space between the two , the last one 3 Back is enter ...
......
The last line :3 After spaces , Output 1, And then go back ;
Ideas
Basic diamond output , It is easy to notice that the absolute value is used to keep the upper and lower symmetry , Control the number of lines and spaces
Code part reference :
#include<stdio.h>
#include<math.h>
int main()
{
int n, j, k, l, m;
scanf("%d", &n);
n = n - 1;
for ( j = -n; j <= n; j++) // The number of control lines is 2n-1
{
for (k = 1; k <= abs(j); k++) // Output spaces per line
printf(" ");
for (l = n - abs(j) + 1; l >= 2; l--)
printf("%d ", n - abs(j) + 1); // Output number ( With spaces )
printf("%d", n - abs(j) + 1); // Output the last number of each line
printf("\n"); // Output carriage return
}
return 0;
} Real output case

边栏推荐
- Template specialization template <>
- Express framework installation and start service
- Module 8 job
- JS prototype and prototype chain Paramecium can understand
- Installing MySQL for Linux
- Pat a - 1010 radical (thinking + two points)
- Phantomjs Usage Summary
- leetcode 91. Decode ways (medium)
- Do you know the memory components of MySQL InnoDB?
- JS - single sign on
猜你喜欢

Error reported when compiling basalt

Byte order: big endian vs little endian

Foundation Consolidation - Flex width is content width

fatal: refusing to merge unrelated histories

1. introduction to MySQL database connection pool function technology points

Nuxt - auto generate dynamic route bug

基于深度学习的视觉目标检测技术综述

Steps to implement a container global component

Installing MySQL for Linux

ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum
随机推荐
Pat a - 1010 radical (thinking + two points)
Overview of visual object detection technology based on deep learning
Muduo simple usage
Using WordPress to create a MySQL based education website (learning notes 2) (technical notes 1) xampp error1045 solution
Template specialization template <>
5. explain function overloading
[cmake command notes]target_ compile_ options
Centos7 installing postgresql12
C. Diluc and Kaeya——Codeforces Round #724 (Div. 2)
时间复杂度
Openvino CPU acceleration survey
Binary String
Browser independent way to detect when image has been loaded
Pat class A - 1007 maximum subsequence sum
MySQL -- how to access the database of a computer in the same LAN (prenatal education level teaching)
Analysis of current mainstream video coding technology | community essay solicitation
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;
How to type Redux actions and Redux reducers in TypeScript?
Autumn move script a
JMeter associated login 302 type interface