C basics


  1. 1     Print Name and Age in Console


#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Harry Potter\n");
    printf("12");
    return 0;
}


  1. 2  Input User Name and Birth Year. Then outputs Name and Age in the console


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int year,age;
    char name[20];

    printf("Enter Birth Year\n");
    scanf("%d",&year);

    printf("Enter Name\n");
    scanf("%s",&name);

    age=2017-year;

    printf("Your Name is %s\n",name);
    printf("Your Age is %d\n",age);
    return 0;
}



No comments:

Post a Comment