hyfm.net
当前位置:首页 >> 1 121 12321 1234321 C语言程序用For循环,怎么编 >>

1 121 12321 1234321 C语言程序用For循环,怎么编

include main() { float n,s=0,t=1; for(n=1;n

我只知道前四个了,以下是c#中打印的,java中只需改一下输出语句,即将console.write改为system.out.print即可.no1 int i, j; for (i = 0; i { for (j = 0; j { console.write("*"); } console.write("\n"); } no2 int i, j; for (j = 1; j { for (i = 0; i { console.write(

#include#include#define n 7#define kg abs(n/2-i)#define xh ((n/2-abs(n/2-i))*2+1)#define sz xh/2-abs(xh/2-j)+1 void main() { int i,j,k; for ( i=0;i for ( j=0;j for ( j=0;j printf("\n"); } }

#include main() { int i,j; for(i=1;i { for(j=1;j printf(" "); for(j=1;j printf("%d",j); for(j=i-1;j>0;j--) printf("%d",j); printf("\n"); } }

/* 1 121 12321 1234321 123454321 12345654321 1234567654321 12345678765432112345678987654321用C语言编程输出等腰三角形只定义三个变量i,j,k */#include<stdio.h>main(){ int i=0; int j=0; int k=0; for(i=1;i<10;i++) { for(k=1;k<=9-i;k++)

#include <iostream> using namespace std; const int size=6; int main() { unsigned long sum=0; for (int i=1;i<=size;++i) { unsigned long item=0; for (int j=1;j<i;++j) item=item*10+j; for (int k=i;k>=1;--k) item=item*10+k; cout<<item<<endl; sum+=item; }

#include<stdio.h>#include<stdlib.h>#define N 7#define KG abs(N/2-i)#define XH ((N/2-abs(N/2-i))*2+1)#define SZ XH/2-abs(XH/2-j)+1 void main() { int i,j,k; for ( i=0;i<N;i++ ) { for ( j=0;j<KG;j++ ) printf(" "); for ( j=0;j<XH;j++ ) printf("%d",SZ); printf("\n"); } }

#include void main() { printf("%4d\n%5d\n%6d\n%7d\n%6d\n%5d\n%4d\n",1,121,12321,1234321,12321,121,1); }

1、实现这样图形的最简单方法就是使用循环的嵌套.2、c代码示例如下:#include<stdio.h> int main( ) { int i,j,k,m; for(i=1;i<=5;i++) { for(m=1;m<=5-i;m++)printf(" "); for(j=1;j<=i;j++)printf("%d",j); for(k=j-2;k>=1;k--)printf("%d",k); printf("\n"); } }

用数组

相关文档
zxwg.net | jtlm.net | lhxq.net | pznk.net | gtbt.net | 网站首页 | 网站地图
All rights reserved Powered by www.hyfm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com