- 分享
- 0
- 人气
- 0
- 主题
- 3
- 帖子
- 198
- UID
- 19026
- 积分
- 2953
- 阅读权限
- 20
- 注册时间
- 2005-10-14
- 最后登录
- 2018-9-19
- 在线时间
- 1609 小时
|
刚写好的,拿去参考吧 (不知道对不对)
代码:- /******************************************************************************
- * File: hbox.c
- *
- * Purpose: Produce a hollow box using asterisk symbol using for loop.
- * Author: Dhilip89
- * Date: 9-Oct-09
- * Notes:
- * Write a program using for loops to produce a hollow box using the
- * asterisk (*) symbol. The program should prompt the user for
- * the height of the hollow box and check to see that the user
- * entered a number greater than or equal to 3 and less than or
- * equal to 40. If the user enters an invalid number, the program
- * will print an error message and exit. If the user enters a
- * valid number the program will print a hollow box of height and
- * width n, where n is the number the user entered at the console.
- *
- ******************************************************************************/
- #include <stdio.h>
- int main(void) {
- int iSize, iMin = 3, iMax = 40;
- int i, j;
- printf("Enter the size (Between %d ~ %d): ", iMin, iMax);
- scanf("%d", &iSize);
- if ((iSize >= iMin) && (iSize <= iMax))
- {
- for (i = 1; i <= iSize; i++)
- {
- for (j = 1; j <= iSize; j++)
- {
- if ((i == 1) || (i == iSize))
- {
- printf("*");
- }
- else if ((j == 1) || (j == iSize))
- {
- printf("*");
- }
- else
- {
- printf(" ");
- }
- }
- printf("\n");
- }
- }
- else
- {
- printf("Error: Invalid value entered!\n");
- }
- return 0;
- }
复制代码 结果:
[ 本帖最后由 Dhilip89 于 2009-10-9 01:46 PM 编辑 ] |
|