current position:Home>Decipher the password and there is no result after running?

Decipher the password and there is no result after running?

2022-02-02 18:33:20 CSDN Q & A

img


######

#include <stdio.h>int main(){    int i,j;    char a[20];    for(i=0;a[i]='\n';i++)    {        scanf("%c",a[i]);            break;    }    for(j=0;j<=i;j++)    {            if(a[j]<='z'&&a[j]>='a'||a[j]<='Z'&&a[j]>='A')                a[j]=a[j]+4;            }    for(j=0;j<=i;j++)        printf("%d",a[j]);                return 0; } 
Run without result

img

My solution ideas and tried methods
Can output the results correctly



Refer to the answer 1:

For reference :

#include<stdio.h>int main(){    char a[256];    int  i = 0;    while ((a[i] = getchar()) && a[i] != '\n')    {        if (a[i] >= 'A' && a[i] <= 'Z')            a[i] = (a[i] - 'A' + 4) % 26 + 'A';        else if (a[i] >= 'a' && a[i] <= 'z')            a[i] = (a[i] - 'a' + 4) % 26 + 'a';        i++;    }    a[i] = '\0';    printf("%s\n", a);    return 0;} 



Refer to the answer 2:



Refer to the answer 3:
  #include <stdio.h>int main(){    int i,j;    char a[20];    for(i=0;;i++)    {        // Input to add &        scanf("%c",&a[i]);            if(a[i]=='\n')break;                }    // the last one a[i] It's line breaking , So the subscript should be [0,i-1]    i = i-1;    for(j=0;j<=i;j++)    {        // If it is beyond the range of letters, start from the beginning             if(a[j]<='z'&&a[j]>='a')                a[j]='a' + (a[j]-'a'+4)%26;             else if(a[j]<='Z'&&a[j]>='A')                a[j]='A' + (a[j]-'A'+4)%26;     }    for(j=0;j<=i;j++)    // For output characters %c        printf("%c",a[j]);    return 0; } 



Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021833186679.html

Random recommended