C help

Hecker

Well-known member
  • Apr 18, 2022
    6,175
    4,483
    113
    24
    Dinosaur, Colorado
    menna code eka

    #include <stdio.h>
    int main()
    {
    /*name*/
    char name[20];
    printf("What is your name? ");
    //scanf("%s",&name);
    fgets(name,20,stdin);
    printf("Your name is %s. \n",name);

    /*age*/
    int age;
    printf("What is your age now? ");
    scanf("%d",&age);
    printf("You are %d years old\n",age);

    /*gpa*/
    float gpa;
    printf("What is your gpa? ");
    scanf("%f",&gpa);
    printf("My gpa is %f.\n",gpa);

    //food
    char food[20];
    printf("What is your favourite food? ");
    fgets(food,20,stdin);
    printf("Your favourite food is %s.",food);

    return 0;
    }

    Output eka eddi food kiyana input eka ganne scanf walin gannawa fgets walin space thiyanna puluwan nisa damme!

    What is your name? Perera S
    Your name is Perera S
    .
    What is your age now? 20
    You are 20 years old
    What is your gpa? 2.5
    My gpa is 2.500000.
    What is your favourite food? Your favourite food is
    .
    Process returned 0 (0x0) execution time : 20.708 s
    Press any key to continue.

    mokakkda awla meke ??????
     

    Hecker

    Well-known member
  • Apr 18, 2022
    6,175
    4,483
    113
    24
    Dinosaur, Colorado