U E D R , A S I H C RSS

새싹교실/2011/AmazingC/과제방


과제 1.

이가희 과제제출!!

1.
#include <stdio.h>

int main()
{
	int star, row1, row2, blank;

	for(row1=7;row1>0;row1--) {
		for(star=0;star+row1>0;star--) {
			printf("*");
		}
		for(blank=0;blank<-2*row1+15;blank++) {
			printf(" ");
		}
		for(star=0;star+row1>0;star--) {
			printf("*");
		}
		printf("\n");
	}

	for(row2=0;row2<6;row2++) {
		for(star=0;star<row2+2;star++) {
			printf("*");
		}
		for(blank=0;blank<-2*row2+11;blank++) {
			printf(" ");
		}
		for(star=0;star<row2+2;star++) {
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

//맨 첫 줄이랑 맨 마지막 줄 * 13개 만드는 건 알 거 같으면서도 모르겠네요ㅜㅜ


2.
#include <stdio.h>

int main()
{
	int star,blank,row;

	//part 1
	printf("           *\n");

	//part2
	for(row=1;row<=4;row++)
	{
		for(blank=1;blank+row<=10;blank++) printf(" ");
		printf("**");
		for(blank=1;blank<=2*row-1;blank++) printf(" ");
		printf("**\n");
		if(row==4) {
			for(blank=1;blank<=7;blank++) printf("*");
			for(blank=1;blank<=2*row+1;blank++) printf(" ");
			for(blank=1;blank<=7;blank++) 
			{
				printf("*");
				if(blank==7) printf("\n");
			}
		}
	}

	//part3
	for(row=1;row<=3;row++)
	{
		for(blank=1;blank<=2*row-1;blank++) printf(" ");
		printf("**");
		for(blank=1;blank<=21-4*row;blank++) printf(" ");
		printf("**\n");
	}

	//part4
	for(row=1;row<=2;row++)
	{
		for(blank=1;blank<=-2*row+5;blank++) printf(" ");
		printf("**");
		for(blank=1;blank<=9+4*row;blank++) printf(" ");
		printf("**\n");
	}

	//part5
	for(row=4;row>=1;row--)
	{
		if(row==4)
		{
			for(star=1;star<=7;star++) printf("*");
			for(blank=1;blank<=2*row+1;blank++) printf(" ");
			for(star=1;star<=7;star++) {
				printf("*");
				if(star==7) printf("\n");
			}
		}
		for(blank=1;blank+row<=10;blank++) printf(" ");
		printf("**");
		for(blank=1;blank<=2*row-1;blank++) printf(" ");
		printf("**\n");
	}

	//part6
	printf("           *\n\n");
	return 0;
}

//아 레알 조잡한거 같아여...ㅠㅠ
//쉽게 짤수 없을까여..ㅠㅠ

3.
#include <stdio.h>

int main()
{
	int front, back, result;

	for(front=1;front<=9;front++) {
		for(back=1;back<=9;back++) {
			result=front*back;
			printf("%dx%d=%d\n",front,back,result);
		}
		printf("\n");
	}

	return 0;
}

4.
#include <stdio.h>

int main()
{
	int a=1;
	printf("%d\n",a);
	a++;
	while(a<30)
	{
		if(a%10==3 || a%10==6 || a%10==9)
		{
			printf("CLAP!\n");
			a++;
		} else {
			printf("%d\n",a);
			a++;
		}
	}
	return 0;
}

박지호 과제제출

1.
#include <stdio.h>

int main()
{
	int i,j,k;
	for(i=0;i<=6;i++){
		if (i==0){
			for(j=1;j<=13;j++) printf("*");
			printf("\n");
		}
		else{
			for(j=1;j<=7-i;j++) printf("*");
			for(k=1;k<=2*i-1;k++,j++) printf(" ");
			for(;j<=13;j++) printf("*");
			printf("\n");
		}
	}
	for(i=5;i>=0;i--){
		if (i==0) {
			for(j=1;j<=13;j++) printf("*");
			printf("\n");
		}
		else{
			for(j=1;j<=(13-(2*i-1))/2;j++) printf("*");
			for(k=1;k<=2*i-1;k++,j++) printf(" ");
			for(;j<=13;j++) printf("*");
			printf("\n");
		}
	}

	return 0;

}

2.
#include <stdio.h>

int main()
{
	int r,s,b;
	r=1;
	while(r<=5){
		if(r==1){
			for(b=1;b<=11;b++) printf(" ");
			printf("*\n");
		}
		else if(r<=4){
			for(b=1;b<=11-r;b++) printf(" ");
			for(s=1;s<=2;s++) printf("*");
			for(b=1;b<=2*r-3;b++) printf(" ");
			for(s=1;s<=2;s++) printf("*");
			printf("\n");
		}
		else{
			for(s=1;s<=8;s++) printf("*");
			for(b=1;b<=7;b++,s++) printf(" ");
			for(;s<=23;s++) printf("*");
			printf("\n");
		}
		r++;
	}
	r=1;
	while(r<=3){
		for(b=1;b<=2*r-1;b++) printf(" ");
		for(s=1;s<=2;s++) printf("*");
		for(b=1;b<=17-4*(r-1);b++) printf(" ");
		for(s=1;s<=2;s++) printf("*");
		printf("\n");
		r++;
	}
	r=1;
	while(r<=3){
		if(r<=2){
			for(b=1;b<=4-(2*r-1);b++) printf(" ");
			for(s=1;s<=2;s++) printf("*");
			for(b=1;b<=13+4*(r-1);b++) printf(" ");
			for(s=1;s<=2;s++) printf("*");
			printf("\n");
		}
		else{
			for(s=1;s<=8;s++) printf("*");
			for(b=1;b<=7;b++,s++) printf(" ");
			for(;s<=23;s++) printf("*");
			printf("\n");
		}
		r++;
	}
	r=1;
	while(r<=4){
		if(r==4){
			for(b=1;b<=11;b++) printf(" ");
			printf("*\n");
		}
		else{
			for(b=1;b<=6+r;b++) printf(" ");
			for(s=1;s<=2;s++,b++) printf("*");
			for(;b<=15-r;b++) printf(" ");
			for(s=1;s<=2;s++) printf("*");
			printf("\n");
		}
		r++;
	}
	return 0;
}

3.
#include <stdio.h>

int main()
{
	int n,m;
	
	for(n=2;n<=9;n++){
		for(m=1;m<=9;m++) printf("%d x %d = %d\n", n, m, (n*m));
		printf("\n");
	}

	return 0;

}

4.
#include <stdio.h>

int main()
{
	int r;
	r=1;
	while(r<=29){
		if((r%10)%3==0){
			if(r%10!=0) printf("¦\n");//한글로 "짝"이라 썼는데 제눈에만 이상하게 보이는건지 모르겠습니다...복사해도 저데론데 실행하면 제데로 나옵니다(?)
			else printf("%d\n", r);
		}
		else printf("%d\n",r);
		r++;
	}
	return 0;
}
//30미만이라 짧게 끝난듯...

-ㅇㅇ 내가 원래 4번은 30미만까지만 하라고 할려 했는데 안적었나보네 ㅋㅋ-신기호

풀이

1.
#include <stdio.h>

int main(void){
	int rows,stars,blank,numberOfBlanks=0;

	for(rows=0;rows<13;rows++){
		if(rows<=6){
			if(rows==0){
				for(stars=0;stars<13;stars++)
					printf("*");
				printf("\n");
			}
			else{
				numberOfBlanks=2*rows-1;
				for(stars=0;stars<(13-numberOfBlanks)/2;stars++) printf("*");
				for(blank=0;blank<numberOfBlanks;blank++) printf(" ");
				for(stars=0;stars<(13-numberOfBlanks)/2;stars++) printf("*");
				printf("\n");
			}
		}
		else{
			if(rows==12){
				for(stars=0;stars<13;stars++)
					printf("*");
				printf("\n");
			}
			else{
				numberOfBlanks=2*(6-(rows-6))-1;
				for(stars=0;stars<(13-numberOfBlanks)/2;stars++) printf("*");
				for(blank=0;blank<numberOfBlanks;blank++) printf(" ");
				for(stars=0;stars<(13-numberOfBlanks)/2;stars++) printf("*");
				printf("\n");
			}
		}
	}
}

2.
준비중

3.
#include <stdio.h>

int main(void){
	int dan,number;

	for(dan=1;dan<=9;dan++){
		for(number=1;number<=9;number++){
			printf("%d * %d = %d\n",dan,number,dan*number);
		}
	}
}

4.
#include <stdio.h>

int main(void){
	int number,tmp;
	int check=1;

	for(number=1;number<=40;number++){
		tmp=number;
		while(tmp>0){
			if((tmp%10==3)||(tmp%10==6)||(tmp%10==9)){
				printf("clap!");
				check=0;
			}
			tmp/=10;
		}
		printf(" ");
		if(check==1){
			printf("%d ",number);
		}
		check=1;
	}
}

// 위에 40을 임의의 숫자로 바꾸면 모든 경우의 결과물을 볼 수 있습니다.

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:41
Processing time 0.0361 sec