1. 문제에 나온 그림대로 출력하세요. (중첩 for문 사용)
1)
*
*
*
*
*
#include <stdio.h>
int main()
{
int
cnum=0;
int
count;
int
count1;
for(count=0;
5 > count ;count++)
{
for(count1=0;
cnum>=count1; count1++)
{
printf("%c",32);
}
printf("*\n");
cnum++;
}
return
0;
}
2)
*
*
*
*
*
#include
<stdio.h>
int
main()
{
int cnum=5;
int count;
int count1;
for(count=0; 5 > count ;count++)
{
for(count1=0;
cnum>=count1; count1++)
{
printf("%c",32);
}
printf("*\n");
--cnum;
}
return 0;
}
2. 출력할 줄의 개수를 입력받은 후 직삼각형을 다음과 같이
출력하세요. (중첩 for문 사용)
줄 개수 입력 : 5
*
* *
* * *
* * * *
* * * * *
#include
<stdio.h>
int
main()
{
int cnum=0;
int count;
int count1;
for(count=0; 5 > count ;count++)
{
for(count1=0;
cnum>=count1; count1++)
{
printf("*");
}
printf("\n");
cnum++;
}
return 0;
}
3. 다음과
같은 형태로 문자열이 출력되는 프로그램을 작성하시오. (중첩 for문
사용)
1)
A
A B
A B C
A B C D
A B C D E
#include
<stdio.h>
int
main()
{
char ch[5]="ABCDE";
int count;
int chcnt;
for(count=0; 4>=count; count++)
{
for(chcnt=0;
count>=chcnt; chcnt++)
{
printf("%c",
ch[chcnt]);
}
printf("\n");
}
return 0;
}
2) a
b a
c b a
d c b a
e d c b a
#include
<stdio.h>
int main()
{
char ch[5]="ABCDE";
int count;
int chcnt=0;
int cnt;
for(count=4; 0<=count; count--)
{
for(cnt=1;
cnt<=count ;cnt++)
{
printf("
");
}
for(cnt=chcnt;
0<=cnt; cnt--)
{
printf("%c",
ch[cnt]);
}
chcnt++;
printf("\n");
}
return 0;
}
3. 문제에 나온 그림대로 출력하세요. (중첩 for문 사용)
* *
* *
* *
*
* *
* *
* *
#include
<stdio.h>
int main()
{
int cnt;
int cnt1=5;
int i,k;
for(cnt=1; 4>=cnt; cnt++)
{
for(i=1; i<cnt; i++)
{
printf(" ");
}
if(4>cnt)
{
printf("*");
}
for(k=1; k<=cnt1; k++)
{
printf(" ");
}
printf("*\n");
cnt1=cnt1-2;
}
cnt1=1;
for(cnt=1; 3>=cnt; cnt++)
{
for(i=2; i>=cnt; i--)
{
printf(" ");
}
printf("*");
for(k=1; k<=cnt1; k++)
{
printf(" ");
}
printf("*\n");
cnt1=cnt1+2;
}
return 0;
}
'C언어 > 과제' 카테고리의 다른 글
C언어 과제 08 (0) | 2010.10.25 |
---|---|
C언어 도전과제 01 (소수와 합성수를 판단하여라) (0) | 2010.10.20 |
C언어 과제 06 (0) | 2010.10.14 |
C언어 과제 05 (프로그램 작성) (0) | 2010.10.11 |
C언어 과제 03 (0) | 2010.10.06 |