Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202565
  • 博文数量: 37
  • 博客积分: 4624
  • 博客等级: 上校
  • 技术积分: 433
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-10 14:06
文章分类

全部博文(37)

文章存档

2012年(6)

2011年(25)

2008年(6)

我的朋友

分类: LINUX

2011-12-28 18:13:57

直接上代码:
  1. #include <stdio.h>

  2. /*#define JUMP*/

  3. int main()
  4. {
  5.     /*
  6.     char ch;
  7.     while ((ch = getchar()) != EOF) {
  8.         putchar(tolower(ch));
  9.     }
  10.     */
  11.     
  12.     char c = 'A';
  13.     signed char sc = -123;
  14.     unsigned char uc = 123;

  15.     short s = 123;
  16.     signed short ss = -123;
  17.     unsigned short us = 123U;

  18.     int i = 123;
  19.     signed int si = -123;
  20.     unsigned int ui = 123U;

  21.     long l = 123L;
  22.     signed long sl = -123L;
  23.     unsigned long ul = 123UL;

  24.     float f = 123.456F;
  25.     double d = 123.456;
  26.     long double ld = 123.456L;

  27.     char str[32] = "abcdefg";

  28. #ifdef JUMP
  29.     /* input */
  30.     printf("input char:");
  31.     scanf("%c", &c);
  32.     printf("input signed char:");
  33.     scanf("%c", &sc);
  34.     printf("input unsigned char:");
  35.     scanf("%c", &uc);
  36.     
  37.     printf("input short:");
  38.     scanf("%hd", &s);
  39.     printf("input signed short:");
  40.     scanf("%hd", &ss);
  41.     printf("input unsigned short:");
  42.     scanf("%hd", &us);
  43.     
  44.     printf("input int:");
  45.     scanf("%d", &i);
  46.     printf("input signed int:");
  47.     scanf("%d", &si);
  48.     printf("input unsigned int:");
  49.     scanf("%ud", &ui);

  50.     printf("input long:");
  51.     scanf("%ld", &l);
  52.     printf("input signed long:");
  53.     scanf("%ld", &sl);
  54.     printf("input unsigned long:");
  55.     scanf("%ld", &ul);
  56.         
  57.     printf("input float:");
  58.     scanf("%f", &f);
  59.     printf("input double:");
  60.     scanf("%lf", &d);
  61.     /*can not find input long double method*/
  62.     /*printf("input long double:");
  63.     scanf("%f", &ld);*/
  64.     
  65.     printf("input char[]:");
  66.     scanf("%s", str);
  67. #endif

  68.     /*format input*/
  69.     scanf("char%csigned char%cunsigned char%cshort%hdint%dlong%ldfloat%fchar[]%s", &c, &sc, &uc, &s, &i, &l, &f, str);
  70.     
  71.     /* output */
  72.     printf("\n");
  73.     printf("char\t\t:%20c:\n", c);
  74.     printf("signed char\t:%20c:\n", sc);
  75.     printf("unsigned char\t:%20c:\n", uc);

  76.     printf("short\t\t:%20.2hd:\n", s);
  77.     printf("signed short\t:%20.2hd:\n", ss);
  78.     printf("unsigned short\t:%20.2hd:\n", us);

  79.     printf("int\t\t:%20.2d:\n", i);
  80.     printf("signed int\t:%20.2d:\n", si);
  81.     printf("unsigned int\t:%20.2d:\n", ui);

  82.     printf("long\t\t:%20.2ld:\n", l);
  83.     printf("signed long\t:%20.2ld:\n", sl);
  84.     printf("unsigned long\t:%20.2ld:\n", ul);

  85.     printf("float\t\t:%-20.2f:\n", f);
  86.     printf("double\t\t:%-20.2f:\n", d);
  87.     printf("long double\t:%-20.2Lf:\n", ld);

  88.     printf("char[]\t\t:%-20s\n", str);
  89. }
阅读(3423) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~