fnhp.net
当前位置:首页 >> 编写程序输入N的值(0<N<10),输出一个数字金字塔 >>

编写程序输入N的值(0<N<10),输出一个数字金字塔

clear for i=1 to 9 for j=1 to 2*i-1 step 1??i next?next

Dim i As Integer Dim j As Integer Dim n As Integer Private Sub Command1_Click() Form1.Cls n = Val(Text1.Text) If n <= 0 Or n >= 10 Then MsgBox "输入范围错误,请输入010之间的整数", , "输入错误" Text1.Text = "" End If For

两个for循环 一个控制输出行数 一个控制输出数字

#include int main(){ int num,i,j; printf("请输入金字塔的层数"); scanf("%d",&num); for(i=0;i for(j=i+1;j printf(" "); for(j=0;j printf("*"); printf("\n"); } }//你试试吧

c++语言:#include&lt;iostream&gt;using namespace std;int main(){ int n; int i,m,sum; double ave; cout&lt;&lt;"how many numbers do you want to do average?"; cin&gt;&gt;n; for(i=0;i&lt;n;i++) {cin&gt;&gt;m; sum+=m; } ave=sum/n; cout&lt;&lt;"

#include<stdio.h>#include<stdlib.h> main() { int i,j,k,a; printf("请输入层数:"); scanf("%d",&a); for(i=1;i<=a;i++) { for(k=1;k<=a-i;k++) printf(" "); for(j=1;j<=2*i-1;j++) { printf("%d",i); } printf("\n"); } system("pause"); } 这个是金字塔形的!!!

#include "stdio.h" void main() { int n; printf("请输入n的值:"); scanf("%d",&n); while(n>0) { if(n>1) { printf("**\n"); } else { printf("*\n"); } n--; } }

include<stdio.h> int main() { int fun(int n); int i,n,sum=0; scanf("%d",&n); if(n<=0||n>=10) { prinntf("Error ,Input the value of 1 to 9!\n"); return 0; } for(i=1;i<n;i+=2) sum+=fun(i); sum+=fun(n); printf("%d\n",sum); return 0; } int fun(int n)

void pyramid(int n){ int i,j; for(i=1;1<=n;i++){//循环中是i<=n,你写的是1<=n for(j=1;j<=n-i;j++) printf(" "); for(j=1;j<=i;j++) printf("%d",i); printf("\n"); }

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