opurag

prat

Oct 10th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. q1
  2. [7:52 pm, 10/10/2022] Pratiyush DSU B3: #include <stdio.h>
  3. int add(int a, int b)
  4. {
  5. return(a+b);
  6. }
  7. int sub(int a, int b)
  8. {
  9. return(a-b);
  10. }
  11. int multiply(int a, int b)
  12. {
  13. return(a*b);
  14. }
  15. float devide(int a, int b)
  16. {
  17. if (b=0)
  18. {
  19. return(-999999);
  20. }
  21. else{
  22. return(a/b);
  23. }
  24. }
  25. int main()
  26. {
  27. int x,y,z,ch,con=1;
  28. while(con=1)
  29. {
  30. printf("enter 0 for exit\nenter the choice\n'1' for adding\n'2' for substraction\n'3' for multiplication\n'4' for division");
  31. scanf("%d",&ch);
  32. if (ch==0)
  33. {
  34. con=0;
  35. break;
  36. }
  37. printf("enter the two numbers");
  38. scanf("%d%d",&x,&y);
  39. switch (ch)
  40. {
  41. case 1:
  42. printf("the sum is %d",add(x,y));
  43. break;
  44. case 2:
  45. printf("the subtraction is %d",sub(x,y));
  46. break;
  47. case 3:
  48. printf…
  49. [7:53 pm, 10/10/2022] Pratiyush DSU B3: q2
  50. [7:53 pm, 10/10/2022] Pratiyush DSU B3: #include <stdio.h>
  51. int rev (int n )
  52. {
  53. int rem;
  54. if(n==0)
  55. {
  56. return 0;
  57. }
  58. else{
  59. rem=n%10;
  60. printf("%d",rem);
  61. return(rem+rev(n/10));
  62. }
  63. }
  64. int main()
  65. {
  66. int num;
  67. printf("enter the number");
  68. scanf("%d",&num);
  69. printf("\n%d",rev(num));
  70. return 0;
  71. }
  72. Ok thanks
  73. 3,4,5?
  74. bhai ussi pdf se karlo
  75. Ok
  76. What time are you coming to clg ?
  77. At 8
  78. Where ru?
  79. Ground floor
  80. Lab?
  81. Hmmm
  82. Ok will come there
  83. Hm
  84. Kya hmm
  85. Aao saale
  86. [8:42 am, 11/10/2022] Pratiyush DSU B3: q3
  87. [8:42 am, 11/10/2022] Pratiyush DSU B3: #include <stdio.h>
  88. void main()
  89. {
  90. int a[100][100],b[100][100],c[100][100],i,j,k,r1,c1,r2,c2,sum;
  91. printf("enter the number of rows and column of mm1trix \n");
  92. scanf("%d%d",&r1,&c1);
  93. printf("enter the elements in matrix1");
  94. for(i=0;i<r1;i++)
  95. for(j=0;j<c1;j++)
  96. {
  97. scanf("%d",(*(a + i) + j));
  98. }
  99. printf("enter the number of rows and column of mm1trix \n");
  100. scanf("%d%d",&r2,&c2);
  101. if(c1!=r2)
  102. {
  103. printf("error");
  104. }
  105. else{
  106. printf("enter the elements in matrix2");
  107. for(i=0;i<r2;i++)
  108. for(j=0;j<c2;j++)
  109. {
  110. scanf("%d",(*(b + i) + j));
  111. }
  112.  
  113. }
  114. for(i=0;i<r1;i++)
  115. {
  116. for(j=0;j<c2;j++)
  117. {
  118. for (k=0;k<c1;k++)
  119. {
  120. sum=sum+(((a + i) + k)) * (((b + k) + j));
  121. }
  122. ((c + i) + j)=sum;
  123. sum=0;
  124. }
  125. }
  126. printf("the multiplicated of two matrix");
  127. for(i=0;i<r1;i++)
  128. {
  129. for(j=0;j<c2;j++)
  130. {
  131. printf("%d\t",((c + i) + j));
  132. }
  133. printf("\n");
  134. }
  135. }
  136. [8:42 am, 11/10/2022] Pratiyush DSU B3: q5
  137. [8:42 am, 11/10/2022] Pratiyush DSU B3: #include <stdio.h>
  138. void linear(int a[100],int n)
  139. {
  140. int i, toSearch, found;
  141. printf("\nEnter element to search: ");
  142. scanf("%d", &toSearch);
  143.  
  144. found = 0;
  145. for(i=0; i<n; i++)
  146. {
  147. if(a[i] == toSearch)
  148. {
  149. found = 1;
  150. break;
  151. }
  152. }
  153. if(found == 1)
  154. {
  155. printf("\n%d is found at position %d", toSearch, i + 1);
  156. }
  157. else
  158. {
  159. printf("\n%d is not found in the array", toSearch);
  160. }
  161. }
  162. void binary(int a[100],int n)
  163. {
  164. int c, first, last, middle, search;
  165. printf("Enter the value to find:\n");
  166. scanf("%d",&search);
  167. first = 0;
  168. last = n - 1;
  169. middle = (first+last)/2;
  170. while (first <= last)
  171. {
  172. if (a[middle] < search)
  173. {
  174. first = middle + 1;
  175. }
  176. else if(a[middle] > search)
  177. {
  178. last = middle - 1;
  179. middle = (first + last)/2;
  180. }
  181. else if(a[middle] == search)
  182. {
  183. printf("%d is present at index %d.\n", search, middle+1);
  184. break;
  185. }
  186. }
  187. if (first > last)
  188. printf("Not found! %d is not present in the list.\n", search);
  189. }
  190. void main()
  191. {
  192. int a[100],c,n,d,con=1,ch,swap;
  193. printf("Enter number of elements:\n");
  194. scanf("%d",&n);
  195. printf("Enter %d integers:\n", n);
  196. [8:42 am, 11/10/2022] Pratiyush DSU B3: for (c=0; c < n; c++)
  197. {
  198. scanf("%d",&a[c]);
  199. }
  200. for (c=0 ; c<n-1; c++)
  201. {
  202. for (d=0 ; d <n-c-1; d++)
  203. {
  204. if (a[d] > a[d+1])
  205. {
  206. swap = a[d];
  207. a[d] = a[d+1];
  208. a[d+1] = swap;
  209. }
  210. }
  211. }
  212. while(con=1)
  213. {
  214. printf("enter 0 for exit\nenter the choice\n'1' for linear search\n'2' for binary search\n");
  215. scanf("%d",&ch);
  216. if (ch==0)
  217. {
  218. con=0;
  219. break;
  220. }
  221. else
  222. {
  223. switch (ch)
  224. {
  225. case 1:
  226. linear(a,n);
  227. break;
  228. case 2:
  229. binary(a,n);
  230. break;
  231. default:
  232. printf("error");
  233. break;
  234. }
  235. }
  236. }
  237. }
Advertisement
Add Comment
Please, Sign In to add comment