Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program that slices sequence in half, and sets the first half as the second half and vice versa */
- /* ALEXANDROS AGRAFIOTIS, ECE UTH, 27/11/2020 */
- #include <stdio.h>
- #define SIZE 32
- int main(int argc, char* argv[]){
- char arr[SIZE],character,temporary;
- int count=0,i;
- /* Reading characters until max size is reached
- or character '$' is given as input */
- do{
- scanf(" %c",&character);
- if(character != '$'){
- arr[count] = character;
- count++;
- }
- }while(character != '$' && count < SIZE);
- for(i=0; i<count/2; i++){
- /* For odd number of count,skipping the middle part */
- if(count % 2 == 1){
- temporary = arr[i];
- arr[i] = arr[count/2 + i + 1];
- arr[count/2 + i + 1] = temporary;
- }
- /* For even number of count */
- else{
- temporary = arr[i];
- arr[i] = arr[count/2 + i];
- arr[count/2 + i] = temporary;
- }
- }
- for(i=0; i<count; i++){
- printf("%c ",arr[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement