main()
{
int i,l,k,y
printf("输入图1或图2\n")
scanf("%d",&y)
if(y==1)
{
printf("输入得数不要扮嫌弊超过10\n")
scanf("者毕%d",&k)
if(k>=1&&k<10)
{
for(i=1i<=ki )
{
for(l=0l<il )
printf("%d",i)
printf("\n")
}
}
}
if(y==2)
{
printf("输入的数不要超过10\n")
scanf("%d",&k)
if(k>=1&&k<10)
{
for(i=1i<=ki )
{
for(l=0l<il )
printf("*")
printf("\n")
}
for(i=1i<=k-1i )
{
for(l=0l<k-il )
printf("*")
printf("\n"厅族)
}
}
}
}
public class Test6 {public static void main(String[] args) {
final int N=5
for (int i = 1 i <= N*2-1 i++) {
for (int j 升旁锋= 1 j <= Math.abs(N - i) j++) {
System.out.print(" ")
}
for (int k = 1 k <= 2*N-1-Math.abs(i-N)*2 k++) {
if(k==1 || k == 2*N-1-Math.abs(i-N)*2)
System.out.print("*")
else
吵晌 System.out.print(" ")
}
System.out.println()
}
}
}
运行结果启带:
*
* *
* *
* *
* *
* *
* *
* *
*
因为不知道你是要者简输出三角形的星号(根据图形),还是要输出菱形的星号(根据文字),所以两个C++程序我都编写出来给你.
按照给出的图形编写的C++程序如下
#include <iostream>using namespace std
int main()
{
int i,j,N=4
for(i=1i<=Ni++){
for(j=1j<=N-ij++){
cout << " "
}
for(j=1j<=i*2-1j++){
cout << "*"
}
cout << endl
}
return 0
}
按照要求编写的输出菱形星号的C++程序如下
#include <iostream>using namespace std
int main()
{
int i,j,N=4
for(i=1i<=Ni++){
for(j=1j<首春裤=N-ij++){
cout << " "
}
for(j=1j<=i*2-1j++){
cout << "*"
}
cout << endl
}
for(i=N+1i<=2*N-1i++){
森游for(j=1j<=i-Nj++){
cout << " "
}
for(j=1j<=4*N-i*2-1j++){
cout << "*"
}
cout << endl
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)