Question

Can someone help me with this, and it has to be written in the C programming...

Can someone help me with this, and it has to be written in the C programming language:

Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it created.

For example: Input:

Output:

Input: Output:

2BeOrNotToBe 2BeOrN otToBe

ToBeOrNotToBe ToBeOrN otToBe

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<string.h>
int main()
{
char str[1000];
int i,len,lim;
printf("Enter the string :");
gets(str);
len = strlen(str);
if(len%2==0)
{
lim=len/2;
for(i=0;i<lim;i++)
{
printf("%c",str[i]);
}
printf(" ");
for(i=lim;i<len;i++)
{
printf("%c",str[i]);
}
}
else
{
lim=len/2;
for(i=0;i<=lim;i++)
{
printf("%c",str[i]);
}
printf(" ");
for(i=lim+1;i<len;i++)
{
printf("%c",str[i]);
}
}
}

Output:

Enter the string :2BeOrNotToBe 2BeOrN otToBe

Add a comment
Know the answer?
Add Answer to:
Can someone help me with this, and it has to be written in the C programming...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c programming

    Write a c program that reads a string with a maximum length of 30 from the keyboard[1]. The program should then copy the characters from that input string into a second character array (in order of input). However, only if a character is a vowel (a, e, i, o, u) should it be copied into the second array. Once copied, the program should output the values stored in the second array (in order of input). The program should then count...

  • C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...

    C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work. Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...

  • in c++ language please Summary given 2 DNA strands of equal length, compare the bas Given...

    in c++ language please Summary given 2 DNA strands of equal length, compare the bas Given two DNA strands of equal length, write a complete C++ program to compare the corresponding bases, and report mismatches. For example, suppose the input to your program are the following two DNA strands CCATGGTC CCAGTGAC then your program should produce the following output **Differences: 3 In other words, your program should output the first strand, then on the next line output a space if...

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • C++ Programming help, please include comments to help me understand the code. Thank you for helping....

    C++ Programming help, please include comments to help me understand the code. Thank you for helping. Task C: Substitution and Hamming Distance For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • C++ Write A Program: //Please DONT use stdio.h or fancy things like classes Given the following...

    C++ Write A Program: //Please DONT use stdio.h or fancy things like classes Given the following header: vector<string> split(string target, string delimiter); implement the function split so that it returns a vector of the strings in target that are separated by the string delimiter. For example: split("10,20,30", ",") should return a vector with the strings "10", "20", and "30". Similarly, split("do re mi fa so la ti do", " ") should return a vector with the strings "do", "re", "mi",...

  • Please, please help! (Programming Assignment: fork gymnastics) Write a C/C++ program (call it string-invert) that takes...

    Please, please help! (Programming Assignment: fork gymnastics) Write a C/C++ program (call it string-invert) that takes a string argument from the command line and outputs the string in reversed order You have two constraints: Constraint 1: Each process can output at most one character. If you want to output more than a single character, you must fork off one or more processes in order to do that, and each of the forked processes in turn outputs a single character t...

  • can someone please help me solve these problem in c++ language and leave useful comments below...

    can someone please help me solve these problem in c++ language and leave useful comments below so i can follow along and know what i am doing /view wa New Tab CSSO IDE 15 THE DIGIT SWAP PROBLEM Write a function named swapDigitPairs() that accepts a positive integer n as an input-output parameter which is changed to a new value similar to n's but with each pair of digits swapped in order. For example: int n = 482596; int old...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT