Last active
September 16, 2017 04:55
-
-
Save thaiall/3f682a040fa1ebdd5d68dcbdede05750 to your computer and use it in GitHub Desktop.
เพิ่มการ printf เพื่อตรวจสอบค่าใน loop ของ forแนวข้อสอบภาษา C จากน้องวงศ์ ผมเอาไปเล่าต่อที่ http://www.thaiall.com/blog/burin/8957/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> // for printf | |
#include <string.h> // for str..() | |
void main() { | |
int i=1, t1=0,t2=0,sum=0; | |
char s1[20]="petty",s2[20]="tiffies"; | |
while(i<3) { | |
if(strcmp(s2,s1)>0) | |
strcat(s2,s1); | |
else if(strcmp(s1,s2)<0) | |
strcpy(s1,s2); | |
else strcpy(s2,s1); | |
i++; | |
} | |
printf("%i %s %s\n",i,s1,s2); // 3 pretty tiffiespettypetty | |
for(i=strlen(s2)-strlen(s1)-1;i>0;i=i-2){ | |
printf("[ %c %i ]\n",s2[i],s2[i]); // [ y 121 ] | |
if(s2[i]%2 ==1){ | |
s1[i] = s1[i]-1; | |
printf(" odd %i\n",s1[i]); | |
t1++; | |
} else { | |
s2[i] = s2[i]+1; | |
printf(" even %i\n",s2[i]); | |
t2+=t1; | |
} | |
sum=t1+t2+i; | |
printf(" %i %s %s\n",i,s1,s2); // [11 to 1] pdtty tifgiesqettypetty | |
} | |
printf("%s %i %s\n",s1,s1[5],s2); // pdtty -1 tifgiesqettypetty | |
printf("%i %zu %zu\n",i,strlen(s1),strlen(s2)); //-1 6 17 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment