Advertisement
Kalhnyxtakias

Untitled

Dec 12th, 2020
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. /* Program that slices sequence in half, and sets the first half as the second half and vice versa */
  2. /* ALEXANDROS AGRAFIOTIS, ECE UTH, 27/11/2020 */
  3. #include <stdio.h>
  4. #define SIZE 32
  5.  
  6. int main(int argc, char* argv[]){
  7.    
  8.     char arr[SIZE],character,temporary;
  9.     int count=0,i;
  10.     /* Reading characters until max size is reached
  11.     or character '$' is given as input */
  12.     do{
  13.         scanf(" %c",&character);
  14.         if(character != '$'){
  15.             arr[count] = character;
  16.             count++;
  17.         }
  18.     }while(character != '$' && count < SIZE);
  19.  
  20.     for(i=0; i<count/2; i++){
  21.         /* For odd number of count,skipping the middle part */
  22.         if(count % 2 == 1){
  23.             temporary = arr[i];
  24.             arr[i] = arr[count/2 + i + 1];
  25.             arr[count/2 + i + 1] = temporary;
  26.         }
  27.         /* For even number of count */
  28.         else{
  29.             temporary = arr[i];
  30.             arr[i] = arr[count/2 + i];
  31.             arr[count/2 + i] = temporary;
  32.         }
  33.     }
  34.  
  35.     for(i=0; i<count; i++){
  36.         printf("%c ",arr[i]);
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement