Advertisement
TAHMID37

Task__abonty

Jul 18th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. //Task 16
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6. bool is_palindrome(const char *message)
  7. {
  8.  
  9.   char *ptr, *rev;
  10.  
  11.     ptr = message;
  12.  
  13.     while (*ptr != '\0')
  14.     {
  15.         ++ptr;
  16.     }
  17.     --ptr;
  18.  
  19.     for (rev =message; ptr >= rev;)
  20.     {
  21.         if (*ptr == *rev)
  22.         {
  23.             --ptr;
  24.             rev++;
  25.         }
  26.         else
  27.             break;
  28.     }
  29.  
  30.     return rev > ptr;
  31.  
  32.  
  33.  
  34.  
  35. }
  36. int main()
  37. {
  38.  
  39.     char message[2000];
  40.     gets(message);
  41.     //puts(message);
  42.     if(is_palindrome(message))
  43.         printf("Yes");
  44.     else
  45.         printf("No");
  46.  
  47.  
  48. }
  49. //Task 11
  50. #include <stdio.h>
  51. #include <string.h>
  52. #include <stdlib.h>
  53. #include <stdbool.h>
  54. double compute_avg_word_length(const char *message)
  55. {
  56.     double tot=0,word=1;
  57.     char *ptr;
  58.     ptr=message;
  59.     for(;*ptr!='\0';ptr++)
  60.     {
  61.        if (*ptr == ' ' && *ptr + 1 != ' ')
  62.                 word++;
  63.        else
  64.            tot++;
  65.     }
  66.  
  67.  
  68.    // printf("%f %f ",tot,word);
  69.  
  70.    return (tot/word );
  71.  
  72.  
  73. }
  74. int main()
  75. {
  76.  
  77.     char message[2000];
  78.     gets(message);
  79.     //puts(message);
  80.    double avg= compute_avg_word_length(message);
  81.    printf("%f",avg);
  82. }
  83. //Task 15
  84. #include <stdio.h>
  85. #include <string.h>
  86. #include <stdlib.h>
  87. #include <stdbool.h>
  88. void  reverse(char *message)
  89. {
  90.    char *first, *last,temp;
  91.    int s=strlen(message),i;
  92.    //printf("%d",s);
  93.    last=message;
  94.    first=message;
  95.    for(i=0;i<s-1;i++)
  96.    {
  97.        last++;
  98.    }
  99.    for(i=0;first<last;i++)
  100.    {
  101.        temp=*last;
  102.        *last=*first;
  103.        *first=temp;
  104.        last--;
  105.        first++;
  106.    }
  107.  
  108.  
  109. }
  110. int main()
  111. {
  112.  
  113.     char message[2000];
  114.     gets(message);
  115.     //puts(message);
  116.     reverse(message);
  117.     puts(message);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement