Naimul_X

Untitled

May 18th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //Question no 1 solution
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. void isPalindrome(char str[])
  9. {
  10.  
  11. int l = 0;
  12. int h = strlen(str) - 1;
  13.  
  14.  
  15. while (h > l)
  16. {
  17. if (str[l++] != str[h--])
  18. {
  19. printf("%s is Not Palindrome", str);
  20. return;
  21. }
  22. }
  23. printf("%s is palindrome", str);
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29. isPalindrome("abba");
  30. isPalindrome("abbccbba");
  31. isPalindrome("Hello");
  32. return 0;
  33. }
  34.  
  35. //problem 2
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40.  
  41. #define str_size 100 //Declare the maximum size of the string
  42.  
  43.  
  44. void main()
  45. {
  46. char str1[str_size], str2[str_size];
  47. int flg=0;
  48.  
  49.  
  50. printf("Input the 1st string : ");
  51. fgets(str1, sizeof str1, stdin);
  52.  
  53. printf("Input the 2nd string : ");
  54. fgets(str2, sizeof str2, stdin);
  55.  
  56. int i=0;
  57.  
  58.  
  59. while(str1[i] == str2[i])
  60. {
  61. if(str1[i] == '\0' || str2[i] == '\0')
  62. break;
  63.  
  64. i++;
  65. }
  66. if(str1[i-1] == '\0' && str2[i-1]=='\0')
  67. {
  68. flg=0;
  69. }
  70. else{
  71. flg=1;
  72. }
  73.  
  74.  
  75. if(flg == 0)
  76. {
  77. printf("\nThe length of both strings are equal and \nalso both strings are equal.\n\n");
  78. }
  79. else{
  80. printf("Not same");
  81. }
  82.  
  83. }
  84.  
  85.  
  86. //question 3
  87.  
  88. #include <stdio.h>
  89. #include <string.h>
  90.  
  91. int main() {
  92. char s[100];
  93. int i;
  94. printf("Enter a string : ");
  95. gets(s);
  96.  
  97. for (i = 0; s[i]!='\0'; i++) {
  98. if(s[i] >= 'a' && s[i] <= 'z') {
  99. s[i] = s[i] - 32;
  100. }
  101. else if(s[i] >= 'A' && s[i] <= 'Z') {
  102. s[i] = s[i] + 32;
  103. }
  104.  
  105. }
  106. printf("\nString = %s", s);
  107. return 0;
  108. }
Add Comment
Please, Sign In to add comment