Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. main()
  6. {
  7. int choose;
  8. char ans;
  9.  
  10. printf("\n***************************************************");
  11. printf("\n* Student Name: Dinh Nguyen Anh Tuan *");
  12. printf("\n* Please select the number for appropriate tasks *");
  13. printf("\n* 1.Quit program *");
  14. printf("\n* 2.Question 2 *");
  15. printf("\n* 3.Question 3 *");
  16. printf("\n* 4.Question 4 *");
  17. printf("\n***************************************************");
  18.  
  19.  
  20. printf("\n\nSelect your number: ");
  21. scanf("%d",&choose);
  22.  
  23. switch(choose)
  24. {
  25. case 1:
  26. exit(0);
  27. case 2:
  28. _flushall();
  29. question2();
  30. break;
  31. case 3:
  32. _flushall();
  33. question3();
  34. break;
  35. case 4:
  36. _flushall();
  37. question4();
  38. break;
  39. }
  40. }
  41.  
  42. question2()
  43. {
  44. char num[100];
  45. int digits;
  46. int i;
  47. int dem;
  48. dem=0;
  49. printf("\n********Counting the digits of a number Program***********");
  50. printf("\nPlease enter a number: ");
  51. scanf("%s",&num);
  52.  
  53. for(i=0;i<strlen(num);i++)
  54. {
  55. if(isdigit(num[i]) == 0) // isdigit = 0 nghia la num[i] ko phai chu so
  56. {
  57. printf("Invalid number");
  58. break;
  59. }
  60. dem++;
  61. }
  62. printf("\nThe number has %d digits",dem);
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. question3()
  70. {
  71. char str[100];
  72. int i;
  73. int dem;
  74. dem=0;
  75.  
  76. printf("\nEnter a string of characters: ");
  77.  
  78. gets(str);
  79.  
  80. //So luong cua tu trong chuoi
  81. for(i=0;i<strlen(str);i++)
  82. {
  83. if(str[i] ==' ')
  84. {
  85. dem++;
  86. }
  87. }
  88. printf("\nThe string has %d words",dem+1);
  89.  
  90. //Moi tu o 1 hang trong chuoi
  91. printf("\nThe string with each word on a different line: \n");
  92.  
  93. for(i=0;i<strlen(str);i++)
  94. {
  95. if(str[i] ==' ')
  96. {
  97. printf("\n");
  98. }
  99. else
  100. {
  101. printf("%c",str[i]);
  102. }
  103. }
  104.  
  105. //Dao nguoc chuoi va xuat ra
  106. printf("\nThe string in reversed order of characters: \n");
  107.  
  108. for(i=strlen(str);i>=0;i--)
  109. {
  110. printf("%c",str[i]);
  111. }
  112. }
  113.  
  114. question4()
  115. {
  116.  
  117. struct detailStudent
  118. {
  119. char name[50];
  120. float csharp_mark;
  121. float java_mark;
  122. float english_mark;
  123.  
  124. }Student[100];
  125.  
  126. int n;
  127. int i;
  128. float total;
  129. float average;
  130.  
  131. printf("\nEnter a number of students: ");
  132. scanf("%d",&n);
  133. //n tu 1-100
  134. while(n<1 || n>100)
  135. {
  136. printf("\nThe user must enter the appropriate number to continue");
  137. printf("\nEnter a number of students: ");_flushall();
  138. scanf("%d",&n);_flushall();
  139. }
  140.  
  141. //Nhap thong tin hoc sinh
  142. printf("\nEnter the datas for each student: ");
  143.  
  144. for(i=0;i<n;i++)
  145. {
  146. printf("\nEnter the detail of student %d",i+1);
  147. printf("\nName: ");_flushall();
  148. gets(Student[i].name);
  149. printf("\nC Sharp Mark: ");_flushall();
  150. scanf("%f",&Student[i].csharp_mark);
  151. printf("\nJava Mark: ");_flushall();
  152. scanf("%f",&Student[i].java_mark);
  153. printf("\nEnglish Mark: ");_flushall();
  154. scanf("%f",&Student[i].english_mark);
  155.  
  156. }
  157.  
  158. //Xuat thong tin hoc sinh
  159. for(i=0;i<n;i++)
  160. {
  161. printf("\n---------Detail of student %d-----------",i+1);
  162. printf("\nName: %s",Student[i].name);
  163. printf("\nC Sharp Mark: %.2f",Student[i].csharp_mark);
  164. printf("\nJava Mark: %.2f",Student[i].java_mark);
  165. printf("\nEnglish Mark: %.2f",Student[i].english_mark);
  166.  
  167. //Tong diem
  168. printf("\nTotal Mark: %.2f",Student[i].csharp_mark+Student[i].java_mark+Student[i].english_mark);
  169.  
  170. //Diem trung binh
  171. printf("\nAverage Mark: %.2f",(Student[i].csharp_mark+Student[i].java_mark+Student[i].english_mark)/4);
  172. }
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement