Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. - 占位符的使用
  2. printf("要输出的内容", 变量);
  3. %d - int
  4. %ld – long int
  5. %lld - long long
  6. %hd – 短整型
  7. %c - char
  8. %f - float
  9. %lf – double
  10. %u – 无符号数
  11. %x – 十六进制输出 int 或者long int 或者short int
  12. %o - 八进制输出
  13. %s – 字符串
  14.  
  15. 占位符的使用注意不要乱用
  16. 样本函数
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19.  
  20. main()
  21. {
  22.  
  23. system("pause");
  24. }
  25.  
  26. 简单的输入学号案例
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31.  
  32.  
  33. main()
  34. {
  35. printf("请输入学生的个数:");
  36. int count;
  37. scanf("%d",&count);
  38. int* pointer = malloc(sizeof(int)*count);
  39. int i;
  40. for(i=0;i<count;i++){
  41. printf("第%d个学生的学号是:",i+1);
  42. scanf("%d",pointer+i);
  43. }
  44.  
  45. for(i=0;i<count;i++){
  46. printf("第%d个学生的学号为:%d\n",i+1,*(pointer+i));
  47.  
  48. }
  49.  
  50. printf("请输入插班生的个数:");
  51. int num;
  52. scanf("%d",&num);
  53. pointer = realloc(pointer,sizeof(int)*(num+count));
  54. for(i=count;i<num+count;i++){
  55. printf("第%d个插班生的学号为:",i+1);
  56. scanf("%d",pointer+i);
  57. }
  58. for(i=count;i<num+count;i++){
  59. printf("第%d个插班生的学号为:%d\n",i+1,*(pointer+i));
  60.  
  61. }
  62.  
  63. system("pause");
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement