Soruce2Html

자료실 2013. 3. 8. 10:45

'자료실' 카테고리의 다른 글

3장 예제  (0) 2013.03.12
2장 예제  (0) 2013.03.06
Posted by 알 수 없는 사용자
,

*예제 p2-1

#include <stdio.h>

int main()
{
 int num;
 num = 2147483647//정수의 최대값
 num = num + 2;
 printf("양의 최대값 보다 2가 큰 값 %d\n", num);
 num = num - 2;
 printf("최대값 %d\n", num);

}

*예제 p2-2

// 키보드로부터 숫자를 입력받아 화면에 출력하는 프로그램
#include <stdio.h>

int main()
{
  int number;
  
  printf("Please enter a number : ");
  scanf("%d"&number);  //'&'해당 변수의 주소 포인트
  printf("The number you typed is %d\n", number);

}

 

*예제 p2-3 


#include <stdio.h>

main()
{
  int x, y;
  x = 2;
  y = x + 5;
  
  //자료형의 경우
  
  printf("The size of int is %3d bytes\n"sizeof(int));
  printf("The size of short is %3d bytes\n"sizeof(short));
  printf("The size of long is %3d bytes\n"sizeof(long));
  
  //변수의 경우
  printf("The size of x is %3d bytes\n"sizeof x);

  //수식의 경우
  printf("The size of (x + 2) is %3d bytes\n"sizeof(x + 2));

}


*예제 p2-4


#include <stdio.h>

int main()
{
  unsigned int num1 = 67U;
  unsigned long int num2 = 89UL;  
  
  printf("%5d: size of 67U is %3d byte\n", num1, sizeof(67U));

  printf("%5d: size of 89UL is %3d byte\n", num2, sizeof(89ul));

}


*예제 p2-5



#include <stdio.h>

int main()
{
  int inum = 23;
  short snum = 23;
  
  printf("size of int 23 is %3d byte\n"sizeof(inum));

  printf("size of short 23 is %3d byte\n"sizeof(snum));

}




*예제 p2-6


#include <stdio.h>

int main()
{
  int number = 67;
  // 10 진수, 8진수, 16진수로 출력
  
  printf("The value of 67 in decimal is %3d\n", number);
  printf("The value of 67 in octal is %3o\n", number);
  printf("The value of 67 in hexa decimal is %3x\n", number);
  
  //8진수와 16진수를 10진수로 화면에 출력
  
  printf("The decimal value of 020 & 0x20 is %5d & %3d\n"0200x20);

}


 

*예제 p2-7


#include <stdio.h>

int main()
{
  float fnumber = 45000.67;
  
  printf("%f\n", fnumber);
  printf("%9.4f\n", fnumber);
  printf("%e\n", fnumber);
  
  
}


 

*예제 p2-9


#include <stdio.h>

int main()
{
  char ch;
  printf("Please enter any character: ");
  scanf("%c"&ch);
  printf("The ASCII code for character %1c is %3d\n", ch, ch);
  
  
  ch = '1' + '1';
  printf("The ASCII code for character %1c is %3d\n", ch, ch);
  return 0;
  
  
}


 *예제 p2-10


#include <stdio.h>

int main()
{
  printf("10진수 65: %c\n"65);
  printf("16진수 40: \x40\n");
  printf("8진수 73: \073\n");
  printf("백슬러쉬 \\, 작은 따옴표 \',큰따옴표 \"\n");
  printf("2 bell sound \a\a\n");
  
  
}


*예제 p2-11


#include <stdio.h>

int main()
{
  char word[30];

  printf("Please enter anything: ");
  scanf("%s", word);
  printf("%s, this is what you typed\n", word);
  
  
}


*예제 p2-15


#include <stdio.h>

main()
{
  int num = 17;
  printf("num +=5: %d\n", num += 5);  //22
  printf("num -=5: %d\n", num -= 5);  //17
  printf("num *=5: %d\n", num *= 5);  //85
  printf("num /=5: %d\n", num /= 5);  //17
  printf("num %=5: %d\n", num %= 5);  //2
  
  return 0;

}


 

*예제 p2-16


#include <stdio.h>

main()
{
  int intA = 14, intB = 3;
  float floatC = 0;

  floatC = intA / intB;
  printf("%f\n", floatC);

  floatC = (float) intA / intB;
  printf("%f\n", floatC);
  
}


 

 

'스마트컨트롤러 > 예제' 카테고리의 다른 글

1장 예제 소스  (0) 2013.03.06
Posted by 알 수 없는 사용자
,

2013.03.07

스마트컨트롤러 2013. 3. 7. 15:15

2013.03.07
*변수는 메모리의 주소대신 사용하는 메모리 공간의 이름, 필요에 따라 변함
*토큰은 프로그램 내에서 어휘적인 최소단위
*식별자를 만드는 방버
   -첫 글자는 영어의 알파벳이나 밑줄(_)이 올 수 있다.
   -그 뒤에는 영어, 숫자, 밑줄이 올 수 있다.
   -하나의 식별자는 보통 32문자까지 허용된다.
*상수(Constant value)는 미리 정해져 바뀌지 않는 값
*unsigned(양수만포함) - 변수 설정 할때 사용
*정수형(char, short, int)
*'Alt누른 상태에서 + 오른쪽 숫자키' => ASCII Code 로 나타남

 

'스마트컨트롤러' 카테고리의 다른 글

2013.03.11  (0) 2013.03.11
2013.03.08  (0) 2013.03.08
2013.03.06  (0) 2013.03.08
2013.03.05  (0) 2013.03.05
2013.03.04  (0) 2013.03.05
Posted by 알 수 없는 사용자
,