Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //Question no 1 solution
- #include <stdio.h>
- #include <string.h>
- void isPalindrome(char str[])
- {
- int l = 0;
- int h = strlen(str) - 1;
- while (h > l)
- {
- if (str[l++] != str[h--])
- {
- printf("%s is Not Palindrome", str);
- return;
- }
- }
- printf("%s is palindrome", str);
- }
- int main()
- {
- isPalindrome("abba");
- isPalindrome("abbccbba");
- isPalindrome("Hello");
- return 0;
- }
- //problem 2
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define str_size 100 //Declare the maximum size of the string
- void main()
- {
- char str1[str_size], str2[str_size];
- int flg=0;
- printf("Input the 1st string : ");
- fgets(str1, sizeof str1, stdin);
- printf("Input the 2nd string : ");
- fgets(str2, sizeof str2, stdin);
- int i=0;
- while(str1[i] == str2[i])
- {
- if(str1[i] == '\0' || str2[i] == '\0')
- break;
- i++;
- }
- if(str1[i-1] == '\0' && str2[i-1]=='\0')
- {
- flg=0;
- }
- else{
- flg=1;
- }
- if(flg == 0)
- {
- printf("\nThe length of both strings are equal and \nalso both strings are equal.\n\n");
- }
- else{
- printf("Not same");
- }
- }
- //question 3
- #include <stdio.h>
- #include <string.h>
- int main() {
- char s[100];
- int i;
- printf("Enter a string : ");
- gets(s);
- for (i = 0; s[i]!='\0'; i++) {
- if(s[i] >= 'a' && s[i] <= 'z') {
- s[i] = s[i] - 32;
- }
- else if(s[i] >= 'A' && s[i] <= 'Z') {
- s[i] = s[i] + 32;
- }
- }
- printf("\nString = %s", s);
- return 0;
- }
Add Comment
Please, Sign In to add comment