Question #46819

Wap to print middle digit of a 6 digit number. Or wap to print middle character of a string.
1

Expert's answer

2014-09-30T00:42:09-0400

Answer on Question #46819, Programming, C++

Problem.

Wap to print middle digit of a 6 digit number. Or wap to print middle character of a string.

Solution.

Code


#include <stdio.h>
#include <string.h>
int main() {
    char character;
    char text[256] = "";
    int length;
    int i;
    // Input
    printf("Enter string: ");
    scanf("%s", text);
    printf("Enter character: ");
    scanf("\n%c", &character);
    length = strlen(text);
    for (i = length; i >= length / 2; i--) {
        text[i + 1] = text[i];
    }
    text[length / 2] = character;
    // New string
    printf("%s", text);
    return 0;
}

Result

Enter string: 123456

Enter character: +

New string: 123+456

http://www.AssignmentExpert.com/</string.h></stdio.h>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS