打印下列图案(用C语言编写程序 12345 1234 123 12 1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印下列图案(用C语言编写程序 12345 1234 123 12 1相关的知识,希望对你有一定的参考价值。
呵呵,这个问题跟打印“*”号的问题差不多,双重for()循环就可以了代码如下:
#include "stdio.h"
main()
int i,j;
for(i=5;i>=1;i++) //这里i的值取5,4,3,2,1
for(j=1;j<=i;j++) //这里j的值取1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
printf("%3d", j);
printf("\n");
j值就是你所要的,输出出来即可~~ 参考技术A #include "Stdio.h"
int main(void)
int i,j;
for(i=5;i>0;i--)
for(j=1;j<=i;j++)
printf("%d",j);
printf(" ");
getch();
你中间是空格就是这样,是按行的话,把printf(" ");换成printf("\n");本回答被提问者采纳 参考技术B 这么少的数据,可以直接输出,比循环快
printf("%s\n","12345");
printf("%s\n","1234");
printf("%s\n","123");
printf("%s\n","12");
printf("%s\n","1");
用java编写菱形
给代码给注释
for(i=1;i<=4;i++)
这个小的for是打印每一行前边的空格
for(j=1;j<=4-i;j++)
System.out.print(" ");
这个是打印星星的
for(j=1;j<=2*i-1;j++)
System.out.print("*");
这个是打印完一行的换行
System.out.println("");
下边的是一样的 只不过每一行的空格和星星数 和上边是翻过来的
for(i=1;i<=3;i++)
for(j=1;j<=i;j++)
System.out.print(" ");
for(j=1;j<=7-2*i;j++)
System.out.print("*");
System.out.println("");
java.sql.SQLException: 无效的列索引
无效的列索引
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)
atoracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5328)
atoracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)
at untitled5.addreader1.validID(addreader1.java:128)
at untitled5.addreader1.jButton1_actionPerformed(addreader1.java:97)
at untitled5.addreader1_jButton1_actionAdapter.actionPerformed(addreader1.java:175)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
代码:String driverName = "oracle.jdbc.OracleDriver";
Driver driver = (Driver) Class.forName(driverName).newInstance();
//连接数据库
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@LONG:1521:orcl", "sysman", "tongfang");
PreparedStatement pstmt = con.prepareStatement(
" insert into reader values(?)");
pstmt.setString(1, str1);
pstmt.setString(2,str2);
pstmt.setString(3,str3);
pstmt.setString(4,str4);
ResultSet res = pstmt.executeQuery();
参考技术A int i,j;总共2个大的for循环 里边有小的 对吧
第一个大的for是打印菱形的上半部分
for(i=1;i<=4;i++)
这个小的for是打印每一行前边的空格
for(j=1;j<=4-i;j++)
System.out.print(" ");
这个是打印星星的
for(j=1;j<=2*i-1;j++)
System.out.print("*");
这个是打印完一行的换行
System.out.println("");
下边的是一样的 只不过每一行的空格和星星数 和上边是翻过来的
for(i=1;i<=3;i++)
for(j=1;j<=i;j++)
System.out.print(" ");
for(j=1;j<=7-2*i;j++)
System.out.print("*");
System.out.println("");
追问
那个i,j可以理解成行和列吗
追答2个大的循环控制的是行
中间2个小的循环控制的要打印的东西
这组程序可以实现很多种图形,先做出图案,根据坐标做出绝对值,空心菱形、三角形,都可以制作,我也是新手,欢迎采纳
public static void draw()
int n=10;
for(int i=1;i<=n;i++)//控制行数
for(int k=n-1;k>=i;k--)//打印空格
System.out.print(" ");
for(int j=1;j<=2*i-1;j++)//打印*
System.out.print("*");
System.out.println();
for(int i=n-1;i>=1;i--)
for(int k=i;k<=n-1;k++)
System.out.print(" ");
for(int j=1;j<=2*i-1;j++)
System.out.print("*");
System.out.println();
参考技术D for(int m=-8;m<=8;m=m+2)
for(int j=1;j<=(Math.abs(m))/2;j++)
System.out.print(" ");
for(int j=1;j<=9-Math.abs(m);j++)
System.out.print("*");
for(int j=1;j<=(Math.abs(m)-1)/2;j++)
System.out.print(" ");
System.out.println();
以上是关于打印下列图案(用C语言编写程序 12345 1234 123 12 1的主要内容,如果未能解决你的问题,请参考以下文章
C语言编程 编写程序,在屏幕上输出下面的图案(要求用for 循环实现)。 * * *