// SnakeMatrix.cpp : Defines the entry point for the console application.
// Create by Xianyi.Ye, May 4,2010
#include "stdafx.h"
#include <iostream.h>
/*
Question: Print a Sanke Matrix as following
i/j 1 2 3 4 5 6
1 1 2 9 10 25 26
2 4 3 8 11 24 27
3 5 6 7 12 23 28
4 16 15 14 13 22 28
5 17 18 19 20 21 30
6 36 35 34 33 32 31
Explain:
"i" is the line number of the matrix.
"j" is the column number of the matrix.
*/
void showMatrix(int n)
{
for(int i=1 ; i<=n ; i++)
{
for(int j=1 ; j<=n ; j++)
{
if(i<=j)//upper triangular matrix
{
if(j%2==0) //j==even number
cout<<(j-1)*(j-1)+i<<" " ;
else //j==odd number
cout<<(j-1)*(j-1)+2*j-i<<" " ;
}
if(i>j) //lower triangular matrix
{
if(i%2==0) //i==even number
cout<<(i-1)*(i-1)+2*i-j<<" " ;
else //i==odd number
cout<<(i-1)*(i-1)+j<<" " ;
}
}
cout<//create new line.
}
}
int main(int argc, char* argv[])
{
showMatrix(6) ;
return 0;
}
Result:

分享到:
相关推荐
Network Calculus: A Theory of Deterministic Queuing Systems for the Internet Author(s) Jean-Yves Le Boudec and Patrick Thiran Publisher: Springer; 1 edition (August 24, 2001) (August 17, 2011) ...
The availability of languages such as C and Java foster the belief that engineers and programmers need only address problems at the highest levels of a program's operation. Yet, even modern coding ...
In this book, we are going to give you an overview of the concepts that you have to understand before you actually start programming in the C language. We will explain to you the different elements ...
### MISRA-C:2004 指南在关键系统中使用C语言的关键知识点 #### 背景介绍及C语言的应用 MISRA-C:2004指南主要针对的是C语言在关键系统中的使用,特别是汽车工业领域内的实时嵌入式应用。随着技术的发展,C语言因其...
He also highlights the role of the community in driving the evolution of the language and the importance of maintaining a strong foundation for future developments. #### Timeline: C++ in Retrospect ...
Stimulus modes and language media: A study of bilinguals STIMULUS MODES AND LANGUAGE MEDIA: A STUDY OF BILINGUALS CAROLYN EMRICK MASSAD Educatimucl Testing Service KAORU YAMAMOTO Pennsylvania...
标题提到的"A lib of Matrix operation for C language"正是这样一个库,它为C语言程序员提供了方便的矩阵操作接口。 矩阵运算库通常包括以下功能: 1. **矩阵创建**:库应提供创建矩阵的功能,可能包括初始化为空...
If you don’t have a lot of time, but still want to learn the latest in C++, you don’t have to learn C first. You might learn more by digging into current language features and classes from the very ...
"C-language-example-code.rar_c language example" 是一个压缩包,包含了900个C语言的经典实例,旨在帮助学习者更好地理解和掌握C语言的基本概念和编程技巧。 这个压缩包分为上下两部分,我们主要关注的是" C 程序...
"C_language_example_of_the_essence.rar_The_Essence"这个压缩包显然是一个聚焦于C语言核心概念的资源集合,旨在帮助学习者理解和掌握C语言的精髓。在这个压缩包中,我们可以期待找到一系列精心挑选的编程示例,...
关于postgresql的C语言连接查询以及数据操作的例子,学习postgresql很好的开始。
《MISRA C:2012 Guidelines for the use of the C language in critical systems》是MIRA Limited出版的一本关于C语言在关键系统中使用的指南,适用于汽车工业和其他对软件可靠性有极高要求的领域。MISRA(Motor ...
逐步介绍如何使用Java 2平台软件来开发使用通用Java 2平台功能的通用电子商务网络应用程序。
1.3 The Ambiguity of Language: Why NLP is Difficult 1.4 Dirty Hands 1.4.1 Lexical resources 1.4.2 Word counts 1.4.3 Zipf’s laws 1.4.4 Collocations 1.4.5 Concordances 1.5 Further Reading 1.6 ...
Description: The OpenSSH suite of tools provides replacements for some of the common administrative tools used today such as telnet, FTP and the r-utilities; yet, these tools, considered insecure ...
mso-bidi-language: AR-SA">本文从C</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; ...
DeepSeek-VL2: Mixture-of-Experts Vision-Language Models for Advanced Multimodal Understanding
Design and Analysis of Algorithms: A Contemporary Perspective April 30, 2019 by Sandeep Sen (Author), Amit Kumar (Author) Paperback: 350 pages Publisher: Cambridge University Press (May 31, 2019) ...
The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 目录结构: Contents Preface Preface ...