Read year from user and convert to integer - C Language Basics

C examples for Language Basics:scanf

Description

Read year from user and convert to integer

Demo Code

#include <stdio.h>
#include <stdlib.h>
int main()/*www .ja  v  a  2s .co  m*/
{
   int methus;
   int you;
   char years[8];
   printf("How old are you?");
   gets_s(years);
   you=atoi(years);
   printf("How old was Jame?");
   gets_s(years);
   methus=atoi(years);
   printf("You are %d years old.\n",you);
   printf("James was %d years old.\n",methus);
   return(0);
}

Result


Related Tutorials