Advertisement
Guest User

Solutions of CSE122 of Fall-17

a guest
Apr 20th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. //01
  2. //(A)
  3.  
  4. 1. I am a DIU student
  5. 2. am a DIU student
  6. 3. a
  7. 4. m a DIU student
  8. 5. m
  9. //(B)
  10. 1. I=5 J=3
  11. 4. I=5 J=3
  12. 5. I=6 J=4
  13. 2. I=6 j=3
  14. 3, K=10
  15.  
  16. //02
  17. //(A)
  18.  
  19. #include <stdio.h>
  20. int main(){
  21. int n;
  22.  
  23. scanf("%d", &n);
  24.  
  25. printf("%d\n", (n * (n + 1)) / 2);
  26.  
  27. return 0;
  28. }
  29.  
  30. //B
  31.  
  32. #include <stdio.h>
  33. int sum(int a){
  34. if(a == 0){
  35. return 0;
  36. }
  37. return a + sum(a - 1);
  38. }
  39.  
  40. int main(){
  41. int n;
  42.  
  43. scanf("%d", &n);
  44.  
  45. printf("%d\n", sum(n));
  46.  
  47. return 0;
  48. }
  49.  
  50. //C
  51.  
  52. #include <stdio.h>
  53. int mul(int a, int b, int c){
  54. return a * b * c;
  55. }
  56.  
  57. int main(){
  58. int a, b, c;
  59.  
  60. scanf("%d %d %d", &a, &b, &c);
  61.  
  62. printf("%d\n", mul(a, b, c));
  63.  
  64. return 0;
  65. }
  66.  
  67. //D
  68.  
  69. #include <stdio.h>
  70. struct Car{
  71. char mod_name[500];
  72. int max_speed;
  73. double wh_size;
  74. };
  75. int main(){
  76. struct Car Mercedes;
  77. struct Car BMW;
  78.  
  79. scanf("%s", Mercedes.mod_name);
  80. scanf("%d %lf", &Mercedes.max_speed, &Mercedes.wh_size);
  81.  
  82. scanf("%s", BMW.mod_name);
  83. scanf("%d %lf", &BMW.max_speed, &BMW.wh_size);
  84.  
  85. printf("Mercedes Model Name: %s\n", Mercedes.mod_name);
  86. printf("Mercedes Maximum Speed: %d kmph\n", Mercedes.max_speed);
  87. printf("Mercedes Wheel Size: %.1lf inches\n\n", Mercedes.wh_size);
  88.  
  89.  
  90. printf("Mercedes Model Name: %s\n", BMW.mod_name);
  91. printf("Mercedes Maximum Speed: %d kmph\n", BMW.max_speed);
  92. printf("Mercedes Wheel Size: %.1lf inches\n", BMW.wh_size);
  93.  
  94. return 0;
  95. }
  96.  
  97.  
  98. //E
  99.  
  100. #include <stdio.h>
  101. int main(){
  102. char str[5000];
  103.  
  104. scanf(" %[^\n]", str);
  105. int len = strlen(str);
  106.  
  107. for(int i = len - 1; i >= 0; i--){
  108. printf("%c", str[i]);
  109. }
  110. printf("\n");
  111.  
  112. return 0;
  113. }
  114.  
  115. //F
  116.  
  117. #include <stdio.h>
  118. int main(){
  119. int arr[10];
  120. int temp;
  121.  
  122. for(int i = 0; i < 10; i++){
  123. scanf("%d", &arr[i]);
  124.  
  125. if(i != 0 && i % 2 == 1){
  126. temp = arr[i - 1];
  127. arr[i - 1] = arr[i];
  128. arr[i] = temp;
  129. }
  130. }
  131.  
  132. for(int i = 0; i < 10; i++){
  133. if(i != 9){
  134. printf("%d ", arr[i]);
  135. } else {
  136. printf("%d\n", arr[i]);
  137. }
  138. }
  139.  
  140. return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement