What's new

Pwede patulong mag run ng ganito sa c programming?

Chillaxxx

Honorary Poster
Joined
Mar 18, 2020
Posts
262
Reaction
43
Points
169
wala kasi akong background. basic steps sana pa'no gumawa yung beginner friendly
received_917094665883374.jpeg
 

Attachments

C:
#include <stdio.h>

int main(void)
{
    char fname[256];
    char lname[256];
    int bir_year, age;
    float weight;
    
    printf("Enter first name: ");
    scanf("%s", fname);
    printf("Enter last name: ");
    scanf("%s", lname);
    printf("Enter your year of birth: ");
    scanf("%d", &bir_year);
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("Enter your weight: ");
    scanf("%f", &weight);
    
    printf("Your name is %s %s.", fname, lname);
    printf(" You were born on %d.", bir_year);
    printf(" You are %d years old.", age);
    printf(" Your weight is %f kg.", weight);
    
    return 0;
}
 
#include <stdio.h> - stdio.h is a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc. If we want to use printf or scanf function in our program, we should include the stdio.h header file in our source code.

int main() indicates that the main function can be called with any number of parameters or without any parameter. On the other hand, int main(void) indicates that the main function will be called without any parameter

type variable_name (char fname[256]) = kaya may 256 jan kasi yan yung pinaka pointer/ireread na byte sa variable mo, bale ginawa kong 256 kasi alam naman nating di mag eexceed sa 256 yung first name at last name mo bale yan yung pinaka max length.

printf yan naman yung function sa pag piprint ng something you want to. (output)
scanf naman yun yung paglalagay mo ng value sa isang variable. (input)

return 0; jan lang yan wag mo na lang alisin. hahahahahahahahaha
 
C:
#include <stdio.h>

int main(void)
{
    char fname[256];
    char lname[256];
    int bir_year, age;
    float weight;
   
    printf("Enter first name: ");
    scanf("%s", fname);
    printf("Enter last name: ");
    scanf("%s", lname);
    printf("Enter your year of birth: ");
    scanf("%d", &bir_year);
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("Enter your weight: ");
    scanf("%f", &weight);
   
    printf("Your name is %s %s.", fname, lname);
    printf(" You were born on %d.", bir_year);
    printf(" You are %d years old.", age);
    printf(" Your weight is %f kg.", weight);
   
    return 0;
}
lods, may tg ka? pwede pa-include ng details ko exactly as variables?
 
Solution:
C:
#include <stdio.h>

int main(void)
{
    char height[100], name[100], birth[200], place[200];
    int age;
    float weight;
   
    printf("Enter first name: ");
    scanf("%[^\n]%*c", name);
    printf("Enter your date of birth: ");
    scanf("%[^\n]%*c", birth);
    printf("Enter your place of birth: ");
    scanf("%[^\n]%*c", place);
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("Enter your weight: ");
    scanf("%f", &weight);
    printf("Enter your height: ");
    scanf("%s", height);
   
    printf("Your name is %s.", name);
    printf(" You were born on %s.", birth);
    printf(" You are %d years old.", age);
    printf(" You were born in %s.", place);
    printf(" Your weight is %f kg.", weight);
    printf(" Your height is %s.", height);
   
    return 0;
}

wag na lang intindihin yung mga numbers hahaha imbento ko lang yan
tapos kudos sa stackoverflow sa regex for scanf.
 

Similar threads

Back
Top