输出数字的形状为三角形

#include <stdio.h>
void main()
{
	int i =1,a = 2, b= 0, n = 0;
	for (int j = 0;i+b<=21;j++)
	{
		n = i;
		printf("%-3d",n);
		for (int k = 0;n+a+k<=21;k++)
		{
			n =n+a+k;
			printf("%-3d",n);
		}
		printf("\n");
		b++;
		i = i+b;
		a++;
	}
}

时间: 2024-08-05 20:07:52

输出数字的形状为三角形的相关文章

LeetCode:Integer to English Words - 按英语读法输出数字对应单词

1.题目名称 Integer to English Words(按英语读法输出数字对应单词) 2.题目地址 https://leetcode.com/problems/integer-to-english-words/ 3.题目内容 英文:Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. 中文:给出一个非负整数

代码实现:输出下列的形状-直角三角形

/* 需求:请输出下列的形状 * ** *** **** ***** */ class Demo2_ForFor { public static void main(String[] args) { for (int i = 1;i <= 5 ; i++) { //外循环决定行数 for (int j = 1;j <= i ;j++ ) { //内循环决定列数 System.out.print("*"); } System.out.println(); //将光标换到下一行

算法初级1:输出数字塔

需求: 输入一个1-9的整数n,输出n行由数字组成的数字塔. 1 222 33333 如上图所示. 解决方法: public class 数字塔 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); cal(n); } private static void cal(int n){ //外层for循环控制输出的层数,内层for循环控制每

java多线程编程(2)交替输出数字和字母

mark一下,不停的看看notify和wait的没有理解 class Printer { int index=0; //输出奇数 public synchronized void printA(int a) { while(index%2==0) { try { this.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } index++; S

Python输出数字金字塔

使用Python输出一个数字金字塔 运行结果: 源代码: ''' Python输出数字金字塔 ''' for x in range(1,10): print(' '*(15-x),end='') n=x while n>=1: print(n,sep='',end='') n-=1 n+=2 while n<=x: print(n,sep='',end='') n+=1 print() 原文地址:https://www.cnblogs.com/yijiahao/p/11740372.html

go练习:交叉输出数字和字母

问题:请使用两个线程,一个输出字母,一个输出数字,交替输出1A2B3C....26Z java的实现 我们来练习使用go实现 package main import ( "fmt" ) func main() { var h = 65 var c, d, e = make(chan int), make(chan int), make(chan int) go func() { for i := 0; i < 26; i++ { <-c fmt.Print(i+1, &qu

递归调用函数-以字符串输出数字

递归输出字符,注意,使用putchar输出一个数字的时候需要加'0',否则.... 1 #include<stdio.h> 2 3 void convert(int n) 4 { 5 int i; 6 if((i=n/10)!=0) 7 { 8 convert(i); 9 } 10 putchar(n%10+'0'); 11 } 12 13 int main(void) 14 { 15 int num; 16 printf("input a num:\n"); 17 sca

[Erlang_Question22]如何按规则位数输出数字

需求:把一个数字指定长度输出 例如: 1 00000001 12 00000012 1203 00001203 123456789 123456789 1234567 01234567 方法一:使用io_lib:format来构造: 方法说明见: %%使用Io:fromat来输出~F.P.PadModC. %% ~F. ---> ~4. 宽度为F %% P. ---> . 无精度要求 %% Pad ---> 0 用Pad填充 %% Mod ---> 没有控制序列修饰符指定 %% C

java 格式化输出数字的方法

在实际工作中,常常需要设定数字的输出格式,如以百分比的形式输出,或者设定小数位数等,现稍微总结如下 主要使用的类:java.text.DecimalFormat 1.实例化对象,可以用如下两种方法: 代码如下: DecimalFormat df=(DecimalFormat)NumberFormat.getInstance(); DecimalFormat df1=(DecimalFormat) DecimalFormat.getInstance(); 因为DecimalFormat继承自Num