廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 5775 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
johnroyer 手機
個人頭像
個人文章 個人相簿 個人日記 個人地圖
特殊貢獻獎
小有名氣
級別: 小有名氣 該用戶目前不上站
推文 x8 鮮花 x505
分享: 轉寄此文章 Facebook Plurk Twitter 版主評分 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[C/C++] 畫 空心菱形
用 * 號畫出一個空心的菱形


#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=0,b=0,chk=1,h;
printf("input h:");
scanf("%d",&h);
for(a=0;a<h;a++) printf(&q ..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容


此文章被評分,最近評分記錄
財富:30 (by codeboy) | 理由: 也許會有更短的~^^


My Blog : Zeroplex
Plurk : Zeroplex
獻花 x2 回到頂端 [樓 主] From:台灣教育部 | Posted:2005-10-13 18:21 |
mmpo
個人頭像
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x5
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

要比短是吧!~~~~
這個不用for和while也照畫....

#include <stdio.h>
#include <stdlib.h>

void test(int max,int now){
if(now==-max)
  return ;
test(max,now-1);
printf("%.*s",now<1?-now:now,"       ");
printf("%.*s \n",(max-(now<1?-now:now))*2,"* * * * * * * * * * * ");  
}

int main(){
int n=8;
test(n,n);
system("pause");
}


[ 此文章被mmpo在2005-11-12 10:10重新編輯 ]

此文章被評分,最近評分記錄
財富:30 (by codeboy) | 理由: 宜確不錯...^^


獻花 x2 回到頂端 [1 樓] From:台灣中華電信 | Posted:2005-10-14 23:06 |
檸檬茶
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x5
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

我這個是按照上面那位大大所法表的
多加一些讓它能做更多種輸入變化

#include <stdio.h>
#include <stdlib.h>

void test(int max,int now){
if(now==-max)
return ;
test(max,now-1);
printf("%.*s",now<1?-now:now,"     ");
printf("%.*s \n",(max-(now<1?-now:now))*2,"* * * * * * * * * * * ");  
}

int main(){
int n;
printf("input n:");
  scanf("%d",&n);
test(n,n);
system("pause");
}


獻花 x0 回到頂端 [2 樓] From:台灣教育部 | Posted:2005-11-14 15:13 |
youchun
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x26
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

如果真的要動態決定數目的話
需要動態產生所需 " " 和 "* " 的數目
不然也可以偷機, 給使用者一定不會超過的數目
複製程式
#include <stdio.h>
#include <stdlib.h>

char * space;
char * star;
void test(int max,int now){
  if(now==-max)
    return ;
  test(max,now-1);
  printf("%.*s",now<1?-now:now, space);
  printf("%.*s \n",(max-(now<1?-now:now))*2, star);
}

int main(){
  int n, i;
  printf("input n:");
  scanf("%d",&n);
  space = (char*)malloc(sizeof(char)*(n + 1));
  star  = (char*)malloc(sizeof(char)*(2*n + 1));
  for(i = 0; i < n; i++) {
    space[i] = 32; // " "
    star[2*i + 1] = 32; // " "
    star[2*i] = 42; // "*"
  }
  space[n] = 0;
  star[2*n] = 0;
  test(n,n);
  free(space);
  free(star);


獻花 x0 回到頂端 [3 樓] From:台灣中華電信 | Posted:2005-11-14 17:18 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.020292 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言