/*
#include <stdio.h>
int main(void)
{
int n=1;
int result=0;
while(n<100)
{
if(n%3 == 0)
{
result += n;
}
n++;
}
printf("1부터 100사이의 모든 3의 배수의 합은 %d입니다.\n", result);
return 0;
}*/
#include <stdio.h>
int main(void)
{
int n;
int result=0;
for(n=1;n<100;n++)
{
if(n%3 == 0)
{
result += n;
}
}
printf("1부터 100사이의 모든 3의 배수의 합은 %d입니다.\n", result);
return 0;
}
/*
#include <stdio.h>
int main(void)
{
int n=1;
int result=0;
do
{
if(n%3 == 0)
{
result += n;
}
n++;
} while(n<100);
printf("1부터 100사이의 모든 3의 배수의 합은 %d입니다.\n", result);
return 0;
}*/
'2학기 > C언어' 카테고리의 다른 글
7장 3번 (0) | 2013.11.09 |
---|---|
7장 2번 (0) | 2013.11.09 |
같은자리 공란만들기 (0) | 2013.11.07 |
while 반복문 7 - 평균값구하기 센티널값 빼기 (0) | 2013.11.07 |
while 반복문 6 (0) | 2013.11.06 |
같은자리 공란만들기같은자리 공란만들기
Posted at 2013. 11. 7. 14:46 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int i, j, m;
for(i=5;i>=1;i--) //y축
{
for(j=1;j<6;j++) //x축
{
if(i!=j)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
'2학기 > C언어' 카테고리의 다른 글
7장 2번 (0) | 2013.11.09 |
---|---|
7장 1번 (0) | 2013.11.09 |
while 반복문 7 - 평균값구하기 센티널값 빼기 (0) | 2013.11.07 |
while 반복문 6 (0) | 2013.11.06 |
while 반복문 5 (0) | 2013.11.06 |
while 반복문 7 - 평균값구하기 센티널값 빼기while 반복문 7 - 평균값구하기 센티널값 빼기
Posted at 2013. 11. 7. 00:05 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int n, grade;
double average, sum;
sum = 0;
n = 0;
grade = 0;
printf("종료하려면 음수를 입력하세요.\n");
while(grade >= 0)
{
printf("성적을 입력하세요 : ");
scanf("%d", &grade);
sum = sum + grade;
n++;
}
sum = sum - grade;
n--;
average = sum / n;
printf("평균은 %lf점입니다.", average);
}
'2학기 > C언어' 카테고리의 다른 글
7장 1번 (0) | 2013.11.09 |
---|---|
같은자리 공란만들기 (0) | 2013.11.07 |
while 반복문 6 (0) | 2013.11.06 |
while 반복문 5 (0) | 2013.11.06 |
while 반복문 4 (0) | 2013.11.06 |
while 반복문 6while 반복문 6
Posted at 2013. 11. 6. 21:46 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int i, n, sum;
i = 0;
sum = 0;
while (i < 5)
{
printf("값을 입력하시오: ");
scanf("%d", &n);
sum = sum + n;
i++;
}
printf("1부터 %d까지의 합은 %d입니다.", n, sum);
}
'2학기 > C언어' 카테고리의 다른 글
같은자리 공란만들기 (0) | 2013.11.07 |
---|---|
while 반복문 7 - 평균값구하기 센티널값 빼기 (0) | 2013.11.07 |
while 반복문 5 (0) | 2013.11.06 |
while 반복문 4 (0) | 2013.11.06 |
while 반복문 3 (0) | 2013.11.06 |
while 반복문 5while 반복문 5
Posted at 2013. 11. 6. 18:12 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int i, n, sum;
printf("정수를 입력하세요 : ");
scanf("%d", &n);
i = 0;
sum = 0;
while (i <= n)
{
sum += i;
i = i + 2;
}
printf("1부터 %d까지의 합은 %d입니다.", n, sum);
}
'2학기 > C언어' 카테고리의 다른 글
while 반복문 7 - 평균값구하기 센티널값 빼기 (0) | 2013.11.07 |
---|---|
while 반복문 6 (0) | 2013.11.06 |
while 반복문 4 (0) | 2013.11.06 |
while 반복문 3 (0) | 2013.11.06 |
while 반복문 2 (0) | 2013.11.06 |
while 반복문 4while 반복문 4
Posted at 2013. 11. 6. 18:11 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int i, n, sum;
printf("정수를 입력하세요 : ");
scanf("%d", &n);
i = 1;
sum = 0;
while (i <= n)
{
sum += i;
i++;
}
printf("1부터 %d까지의 합은 %d입니다.", n, sum);
}
'2학기 > C언어' 카테고리의 다른 글
while 반복문 6 (0) | 2013.11.06 |
---|---|
while 반복문 5 (0) | 2013.11.06 |
while 반복문 3 (0) | 2013.11.06 |
while 반복문 2 (0) | 2013.11.06 |
while 반복문 (0) | 2013.11.06 |
while 반복문 3while 반복문 3
Posted at 2013. 11. 6. 17:57 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int n;
printf("======================\n");
printf(" n n의제곱 \n");
printf("======================\n");
n = 1;
while(n<=10)
{
printf(" %5d %5d\n", n, n*n);
n++;
}
}
'2학기 > C언어' 카테고리의 다른 글
while 반복문 5 (0) | 2013.11.06 |
---|---|
while 반복문 4 (0) | 2013.11.06 |
while 반복문 2 (0) | 2013.11.06 |
while 반복문 (0) | 2013.11.06 |
4차 10번 (0) | 2013.10.31 |
while 반복문 2while 반복문 2
Posted at 2013. 11. 6. 17:48 | Posted in 2학기/C언어#include <stdio.h>
int main()
{
int n;
int i=1;
printf("출력하고 싶은 단 : ");
scanf("%d", &n);
while (i <= 9)
{
printf("%d*%d = %d \n", n, i, n*i);
i++;
}
}
'2학기 > C언어' 카테고리의 다른 글
while 반복문 4 (0) | 2013.11.06 |
---|---|
while 반복문 3 (0) | 2013.11.06 |
while 반복문 (0) | 2013.11.06 |
4차 10번 (0) | 2013.10.31 |
4차 9번 (0) | 2013.10.31 |
#include <stdio.h>
int main()
{
int meter;
int i = 0;
while (i<3)
{
meter = i * 1609;
printf("%d 마일은 %d 미터입니다.\n", i, meter);
i++;
}
}
'2학기 > C언어' 카테고리의 다른 글
while 반복문 3 (0) | 2013.11.06 |
---|---|
while 반복문 2 (0) | 2013.11.06 |
4차 10번 (0) | 2013.10.31 |
4차 9번 (0) | 2013.10.31 |
4차 8번 (0) | 2013.10.31 |
#include <stdio.h>
int main()
{
int n;
printf("입력 : ");
scanf("%d", &n);
switch(n)
{
case 1 : printf("%d\n", n);
case 2 : printf("%d\n", n+1);
case 3 : printf("%d\n", n+2);
default : printf("실행 종료!");
}
return 0;
}
switch는 정수밖에 받지 못하므로 float를 못쓰며 {}를 써주지 않아 오류가 남.
break문은 의도적으로 안쓴것 같아서 냅둠