BLOG ARTICLE DEVELOP | 84 ARTICLE FOUND
- 2006.07.13 06/07/13 숙제
- 2006.07.13 수업내용
- 2006.07.13 자바반문제 C로 풀기 2탄 =.=
- 2006.07.12 06/07/12 숙제
- 2006.07.12 06/07/12 수업내용
- 2006.07.11 06/07/11 숙제
- 2006.07.11 06/07/11 수업내용
- 2006.07.10 06/07/10 숙제
- 2006.07.10 06/07/10 수업내용
- 2006.07.08 자바반문제 C로 풀기 =.=
- 2006.07.07 06/07/07 숙제
- 2006.07.07 06/07/07 수업내용
- 2006.07.06 06/07/06 수업내용
- 2006.07.05 06/07/05 숙제
- 2006.07.05 06/07/05 수업내용
2. 로또
3. 달력
int ary[5]={10,20,30,40,50};
ary[0]=..
*(&ary[0]+0) -> 100
*(&ary[0]+1) -> 104 -> &ary[0]+(1*sizeof(int))
*(&ary[0]+0) = 10;
*(&ary[0]+1) = 20;
*(&ary[0]+2) = 30;
*(&ary[0]+3) = 40;
*(&ary[0]+4) = 50;
*(ary+0)=10;
*(ary+1)=20;
*(ary+2)=30;
*(ary+3)=40;
*(ary+4)=50;
//포인터 표현
ary[0]=10;
ary[1]=20;
ary[2]=30;
ary[3]=40;
ary[4]=50;
//배열표현
포인터간의 연산
&ary[3]-&ary[0] =12
12/4(단위크기)=3
//두 포인터간 거리를 의미
scanf("%d",&ap[i]);
&ap[i] -> &*(ap+i) -> ap+i //로 쓰는것이 바람직
#include <stdio.h>
int main()
{
char startA='A', alpha;
int i,j,k;
for(i=0;i<=26;i++)
{
if(i<13)
{
alpha=startA+i;
for(k=0;k<i;k++)
{
printf(" ");
}
for(j=i;j<26-i;j++)
{
printf("%c",alpha);
alpha++;
}
printf("\n");
}
else if(i==13||i==14)
{
alpha++;
}
else if(i>14)
{
for(k=0;k<26-i;k++)
{
printf(" ");
}
alpha=startA+26-i;
for(j=26-i;j<i;j++)
{
printf("%c",alpha);
alpha++;
}
printf("\n");
}
}
*&a=10;
*:참조연산자//선언시에만 사용
&:주소연산자
int a=0;
int *ap;//포인터변수..
double *dp;
ap=&a;
dp=ap; //불가.. 형식이 다르므로..
//호출은& 받기는* 활용은 그냥??
#include <stdio.h>
/*void swap(int *ap, int *bp)
{
int temp;
temp=*ap;
*ap=*bp;
*bp=temp;
}
*/
input_data(int *ap, int *bp)
{
printf("넣어:");
scanf("%d%d",ap,bp);
}
int main()
{
int a, b;
input_data(&a,&b);
printf("%d\t%d\n",a,b);
return 0;
}
int a;
int *ap=&a;
혹은 int *ap; ap=&a;
*ap=10;//정상
scanf("%d",*ap);// X
scanf("%d",ap);// O
배열
참조의 뜻
기억공간이 된다,Lvalue
그 기억공간의 값,Rvalue
b=a
L=R
int a=10, b;
int *ip=&a;
b=*ip;
*ip=20;
printf("%d",a);
a++=10; //불가 Lvalue가 값이 되어버리므로
배열의 기능
int ary[5]={10,20};//나머지는 0으로 매핑됨
int ary[5]={0,};//0으로 초기화하겠다.
int ary[]={10,20,30,40,50};//유동적
size=sizeof(ary)/sizeof(ary[0]);
for(i=0;i<size;i++)
{
}
printf + %s는 for+ printf + %c 이다.
scanf함수는 마지막에 널문자를 할당해준다.(배열에서%S문자사용시만)
하나씩 넣을때는 마지막에 널을 입력해주지않으면 =.= 안좋음
널문자 자리가 없다면??//에러나가 나거나 쓰레기값이 나옴
char str[500]={'L','O','V','E','\0'};
//나머지는 아스키 코드0으로 채워짐
int를 char로 변환시 모듈러 오퍼레이션때문에 3바이트가 사라짐
int 4바이트 char 1바이트
char str[500]="LOVE";//로도 표현가능
\0//숨어있음
//따라서 5바이트
str="money";
//일단 입력된 문자열은 수정하기 까다롭다
//하나씩 입력..=.= 좌절
//포인터는 입력가능
char*sp="LOVE";
sp="money";
////////////////////////////////////////////////////////////
//받은값을 절대값으로 돌려주기
////////////////////////////////////////////////////////////
#include <stdio.h>
int my_abs(int inputA)
{
int temp;
temp=inputA;
if (temp<0) temp*=(-1);
return temp;
}
int main()
{
int inputA,outputA;
printf("정수를 입력해보련");
scanf("%d",&inputA);
outputA=my_abs(inputA);
printf("%d",outputA);
return 0;
}
////////////////////////////////////////////////////////////
//입력받은 값을 몇제곱하기
////////////////////////////////////////////////////////////
#include <stdio.h>
int my_pow(double inputA, int n)
{
int i=1;
double temp=1.0;
while(i<=n)
{
temp=temp*inputA;
i++;
}
return temp;
}
int main()
{
int inputB=1;
double inputA,outputA;
printf("실수를 입력해보련\n");
scanf("%lf",&inputA);
while(inputB<2)
{
printf("몇제곱 해주리?\n");
scanf("%d",&inputB);
}
outputA=my_pow(inputA,inputB);
printf("%.3lf",outputA);
return 0;
}
////////////////////////////////////////////////////////////
//다이아 모양 출력하기
////////////////////////////////////////////////////////////
#include <stdio.h>
void gonggan(int a)
{
int i;
// printf("%d",a);
if (a<0) a*=(-1);
for(i=0;i<a;i++)
{
printf(" ");
}
}
void byul(int a)
{
int i;
if (a<0) a*=(-1);
// printf("%d",a);
for(i=0;i<a;i++)
{
printf("*");
}
}
int main()
{
int i,n,cs,bs;
n=1;
while(n>=1)
{
printf("가로행 크기를 입력하시오.\n");
scanf("%d",&n);
if (n%2==0) n-=
1;
for(i=1;i<=n;i++)
{
cs=i-(n+1)/2;
if (cs>0) cs*=(-1);
bs=(n+2*cs);
gonggan(cs);
byul(bs);
// printf("%d/%d/%d",cs,bs,cs);
printf("\n");
}
}
return 0;
}
////////////////////////////////////////////////////////////
//양수값만 받아 출력하기
////////////////////////////////////////////////////////////
#include <stdio.h>
int get_pos();
int get_pos()
{
int res=-1;
while(res<0)
{
printf("양수입력 :");
if (scanf("%d",&res)==0) fflush(stdin);
//문자입력시 자동리턴 (scanf 가 0을 돌려줌)되어서 버퍼참조를 자꾸되므로
//버퍼를 날려줘서 해결한다.
// if (res<0) res*=(-1);
if (res<0) printf("음수쟈녀!!!\n");
}
return res;
}
int main()
{
int pos;
pos=get_pos();
printf("양수:%d\n",pos);
return 0;
}
두명이 문제를 못풀어 낑낑대고있어서..
컨셉을 설명해주고 왔다.
심심해서 집에와서 설명해준대로 해본 코딩..
#include <stdio.h>
int main()
{
int inputA, inputB, inputC, temp; //변수선언
int La,Lb,Lc,Ltemp;
int constant=55; //기준값
printf("A값을입력하시오 : "); //값 할당받기
scanf("%d",&inputA);
printf("B값을입력하시오 : ");
scanf("%d",&inputB);
printf("C값을입력하시오 : ");
scanf("%d",&inputC);
La=constant-inputA; //거리측정
Lb=constant-inputB;
Lc=constant-inputC;
La=La*La; //절대거리산정
Lb=Lb*Lb;
Lc=Lc*Lc;
if (Lb>Lc) //크기비교후 자리바꾸기
{
Ltemp=Lb;
Lb=Lc;
Lc=Ltemp;
temp=inputB;
inputB=inputC;
inputC=temp;
}
if (La>Lb)
{
Ltemp=Lb;
Lb=La;
La=Ltemp;
temp=inputB;
inputB=inputA;
inputA=temp;
}
if (Lb>Lc)
{
Ltemp=Lb;
Lb=La;
La=Ltemp;
temp=inputB;
inputB=inputA;
inputA=temp;
}
printf("55에서 가까운 순서는 %d->%d->%d",inputA,inputB,inputC); //출력
return 0;
}
{
case 상수식1: 실행문장1;
case 상수식2: 실행문장2;
case 상수식3: 실행문장3;
case 상수식4: 실행문장4;
default: 실행문장 n;
}
상수식에 변수가 들어갈 수 없음
조건식은 정수가 나와야 함.
char ch;
sizeof ch
sizeof 'A'
6장
// %[flag][width][.precisioin][modifier]변환문자
//매핑문자or정렬방식/공간확보/소수점길이설정/
//flag : #, 0, -
printf("%#o",a);
printf("%9o",a);
printf("%-o",a);
제어문
선택문 : if, switch~case
반복문 : do~while, while, for
분기문 : break, continue, goto, return
if문
관계연산자
<, <=, >, >=, ==, !=
논리연산자
and, or, not
&&, ||, !
short circuit기능
a>10 && a<20
-> 1 && 0
-> 0
#include <stdio.h>
int main()
{
int hakjeom;
scanf("%d",&hakjeom);
// double a,b, res=0;
// scanf("%lf%lf",&a,&b);
// res=a/(b*b);
// if (res>=20 && res<25) printf("100만불짜리 몸매");
// if (res<20 || res>=25) printf("헬스장좀 댕겨라");
// if (res>=25) printf("%lf\t과체중",res);
// else if (res>=20) printf("%lf\t표준체중",res);
// else if (res<20) printf("%lf\t저체중",res);
// if (res>=20 && res<25) printf("100만불짜리 몸매");
// else if (res<20) printf("%lf\t저체중",res);
// else if (res>=25) printf("%lf\t과체중",res);
if (hakjeom >= 90) printf("A\t");
else if (hakjeom >= 80) printf("B\t");
else if (hakjeom >= 70) printf("C\t");
else printf("F\t");
return 0;
}