Advertisement
Maruf_Hasan

Naima

Jun 2nd, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. 1....
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7. int i,flag=0,count=1;
  8. char str[20],ch;
  9. int pos[27];
  10. printf("Enter any string : ");
  11. gets(str);
  12. for(int i=0;i<26;i++)
  13. {
  14. pos[i]=-1;
  15. }
  16. int cnt=1;
  17. for(int i=0;str[i]!='\0';i++)
  18. {
  19. if(str[i]==' ')
  20. continue;
  21. else
  22. {
  23. int c=str[i]-'a';
  24. if(pos[c]==-1)
  25. pos[c]=cnt;
  26. cnt++;
  27. }
  28. }
  29. printf("\n Enter character to be searched :");
  30. scanf("%c",&ch);
  31. int x=ch-'a';
  32. if(pos[x]!=-1)
  33. {
  34. printf("position of %c in the string is :%d\n",ch,pos[x]);
  35. }
  36. else
  37. {
  38. printf("Not found");
  39. }
  40. return 0;
  41. }
  42. .............................
  43. 2...
  44. #include<stdio.h>
  45. #include<math.h>
  46. #include<stdlib.h>
  47. struct point
  48. {
  49. int x,y;
  50. };
  51.  
  52.  
  53.  
  54. int main()
  55. {
  56. point P,Q;
  57. printf("Enter the x,y coordinates of first location \n");
  58. scanf("%d %d",&P.x,&P.y);
  59. printf("Enter the x,y coordinates of second location \n");
  60. scanf("%d %d",&Q.x,&Q.y);
  61. int manhattandis=abs(P.x-Q.x)+abs(P.y-Q.y);
  62. printf("The Manhattan distance between them %d\n",manhattandis);
  63. return 0;
  64. }
  65.  
  66.  
  67. 3...............
  68. #include<stdio.h>
  69.  
  70.  
  71.  
  72. int main()
  73. {
  74. int arr[100];
  75. int n=15;
  76. int *ptr=arr;
  77. for(int i=0;i<n;i++)
  78. {
  79. scanf("%d",ptr);
  80. ptr++;
  81. }
  82. ptr=arr;
  83. for(int i=0;i<n;i++)
  84. {
  85. printf("%d ",*ptr);
  86. ptr++;
  87. }
  88. }
  89. ..................
  90. 4...
  91. #include<stdio.h>
  92.  
  93.  
  94. struct student
  95. {
  96. char name[30];
  97. int id;
  98. char dept[20];
  99. float cgpa;
  100. };
  101.  
  102.  
  103. int main()
  104. {
  105. student S[3];
  106. FILE *fp;
  107. char str[100];
  108. fp=fopen("student.txt","r");
  109. if(fp==NULL)
  110. {
  111. printf("Error opening file");
  112. return 0;
  113. }
  114. while(fgets(str,100,fp)!=NULL)
  115. {
  116. printf("%s\n",str);
  117. }
  118. fclose(fp);
  119. return 0;
  120. }
  121. ..........
  122. 5.
  123.  
  124. #include <stdio.h>
  125.  
  126. #define N 100
  127.  
  128. void transposematrix(int arr[N][N])
  129. {
  130. int row,col;
  131. printf("Enter the number of Row\n");
  132. scanf("%d",&row);
  133. printf("Enter the number of column\n");
  134. scanf("%d",&col);
  135. printf("Enter the numbers\n");
  136. for(int i=0;i<row;i++)
  137. {
  138. for(int j=0;j<col;j++)
  139. {
  140. scanf("%d",&arr[i][j]);
  141. }
  142. }
  143. printf("The Transpose Matrix is:\n");
  144. for(int i=0;i<col;i++)
  145. {
  146. for(int j=0;j<row;j++)
  147. {
  148. printf("%d ",arr[j][i]);
  149. }
  150. printf("\n");
  151. }
  152. }
  153.  
  154.  
  155. int main()
  156. {
  157. int arr[N][N];
  158. transposematrix(arr);
  159. return 0;
  160. }
  161.  
  162.  
  163. 6..........
  164. #include <stdio.h>
  165.  
  166. #define N 100
  167.  
  168. void mirrormatrix(int arr[N][N])
  169. {
  170. int row,col;
  171. printf("Enter the number of Row\n");
  172. scanf("%d",&row);
  173. printf("Enter the number of column\n");
  174. scanf("%d",&col);
  175. for(int i=0;i<row;i++)
  176. {
  177. for(int j=0;j<col;j++)
  178. {
  179. scanf("%d",&arr[i][j]);
  180. }
  181. }
  182. printf("The Mirror Matrix is:\n");
  183. for(int i=0;i<row;i++)
  184. {
  185. for(int j=col-1;j>=0;j--)
  186. {
  187. printf("%d ",arr[i][j]);
  188. }
  189. printf("\n");
  190. }
  191. }
  192.  
  193.  
  194. int main()
  195. {
  196. int arr[N][N];
  197. mirrormatrix(arr);
  198. return 0;
  199. }
  200.  
  201.  
  202.  
  203. 7.
  204. #include <stdio.h>
  205. #define MAX_SIZE 100 // Maximum string size
  206. #define MAX_CHARS 255 // Maximum characters allowed
  207.  
  208.  
  209. int main()
  210. {
  211. char str[MAX_SIZE];
  212. int freq[MAX_CHARS]; // Store frequency of each character
  213. int i = 0, max;
  214. int ascii;
  215.  
  216. printf("Enter any string: ");
  217. gets(str);
  218.  
  219. /* Initializes frequency of all characters to 0 */
  220. for(i=0; i<MAX_CHARS; i++)
  221. {
  222. freq[i] = 0;
  223. }
  224.  
  225.  
  226. /* Finds frequency of each characters */
  227. i=0;
  228. while(str[i] != '\0')
  229. {
  230. ascii = (int)str[i];
  231. freq[ascii] += 1;
  232.  
  233. i++;
  234. }
  235.  
  236.  
  237. /* Finds maximum frequency */
  238. max = 0;
  239. for(i=0; i<MAX_CHARS; i++)
  240. {
  241. if(freq[i] > freq[max])
  242. max = i;
  243. }
  244.  
  245.  
  246. printf("Maximum occurring character is '%c' = %d times.", max, freq[max]);
  247.  
  248. return 0;
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement