current position:Home>C language Mo exercises!

C language Mo exercises!

2022-01-26 22:54:06 CSDN Q & A

Please write the program , Its function is : take s The subscript in the indicated string is even and ASCII Characters with odd values are deleted ,s Put the new string formed by the remaining characters in t In the array referred to .
for example , if s The content of the string is ABCDEFGl2345, Which character C Of ASCII Code value is odd , Subscripts in the array are even , So you have to delete ; And characters 1 Of ASCII Code value is odd , The subscripts in the array are also odd , Therefore... Should not be deleted , Others, and so on . Last t The contents of the array should be BDFl2345.
And write ideas and flow charts




Refer to the answer 1:
#include <stdio.h>#include <string.h>int main(){   char s[256],t[256];   gets(s);   int i,n = 0;   for(i = 0;i < strlen(s);i++){       if((i % 2 == 0 && s[i] % 2 == 0) || (i % 2 == 1)){           t[n++] = s[i];       }   }   t[n] = '\0';   for(i = 0;i < strlen(t);i++){        printf("%c",t[i]);      }   return 0;}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262254044236.html

Random recommended