What's new

C & C++ Patulong sa code mga lods

ALLMIGHTisHERE

Eternal Poster
Joined
Apr 29, 2020
Posts
168
Reaction
2,853
Points
438
#include<stdio.h>

int main(void) {

char a, b, c;
printf("Enter the first character: ");
scanf("%c", &a);
printf("Enter the second character: ");
scanf("%c", &b);
printf("Enter the third character: ");
scanf("%c", &c);



printf("%c\n%c\n%c", a, b, c);


return 0;
}
yung nasa image sana gagawin ko, di ko alam kung bakit di gumagana code ko. Pahelp sana mga lods

Untitled.png
 

Attachments

Last edited:
Instead na
printf("%c\n%c\n%c", a, b, c);
dapat ganito
printf("%c\n%c\n%c", &a, &b, &c);
Hindi mo nalagyan ng ampersand or '&' symbol yung variables nung nag printf ka. Essential yun if you wan to retrieve the value of the variable during printf calls.
 
Instead na
printf("%c\n%c\n%c", a, b, c);
dapat ganito
printf("%c\n%c\n%c", &a, &b, &c);
Hindi mo nalagyan ng ampersand or '&' symbol yung variables nung nag printf ka. Essential yun if you wan to retrieve the value of the variable during printf calls.
sa scanf yan nilalagay lods
 
1659762066797.png

C:
#include <stdio.h>

int main() {

char a[3][3];
char pos[3][20] = {"first", "second", "third"};
int i;

for(i=0;i<3;i++){
    printf("Enter the %s character: ", pos[i]);
    scanf("%s", &a[i]);
}
for(i=0;i<3;i++){
    printf("%s\n", &a[i]);
}
return 0;
}

C:
#include <stdio.h>
char a,b,c;

int main() {
    printf("Enter the first number: ");
    scanf("%c", &a);
    printf("Enter the secound number: ");
    scanf(" %c", &b);
    printf("Enter the third number: ");
    scanf(" %c", &c);
    printf("%c\n%c\n%c", a, b, c);
    
    return 0;
}
 

Attachments

Last edited:
View attachment 2068516
C:
#include <stdio.h>

int main() {

char a[3][3];
char pos[3][20] = {"first", "second", "third"};
int i;

for(i=0;i<3;i++){
    printf("Enter the %s character: ", pos[i]);
    scanf("%s", &a[i]);
}
for(i=0;i<3;i++){
    printf("%s\n", &a[i]);
}
return 0;
}

C:
#include <stdio.h>
char a,b,c;

int main() {
    printf("Enter the first number: ");
    scanf("%c", &a);
    printf("Enter the secound number: ");
    scanf(" %c", &b);
    printf("Enter the third number: ");
    scanf(" %c", &c);
    printf("%c\n%c\n%c", a, b, c);
   
    return 0;
}
grabeh lodi, actually nagets kona. Lalagyan ko lang ng space yung %c sa scanf para hindi maread yung \n everytime you press enter. Salamat parin lods
 
pa explain lods bakit kailangan may space, ang ginawa ko kasi naglagay ako ng dalawang scanf tas gumana siya.
mahirap magexplain pero parang ganito
sa first scanf ok lang pero sa pangalawa habang naginput mareretain kasi yun return key o enter (newline) ng una sa buffer kaya nagescape na manghingi ng input kaya para iignore ng scanf dapat may space
 
Last edited:

Similar threads

Back
Top