Read input with gets_s() function and use atoi() to convert it into an integer value. - C Data Type

C examples for Data Type:int

Description

Read input with gets_s() function and use atoi() to convert it into an integer value.

Demo Code

#include <stdio.h>
#include <stdlib.h>
int getval(void);
int main()/*from w  ww.j  a v a2  s .c o m*/
{
   int age,weight,area;
   float iq;
   printf("Program to calculate your IQ.\n");
   printf("Enter your age:");
   age=getval();
   printf("Enter your weight:");
   weight=getval();
   printf("Enter the your area code:");
   area=getval();
   iq=(age*weight)/area;
   printf("This computer estimates your IQ to be %f.\n",iq);
   return(0);
}
int getval(void)
{
   char input[20];
   int x;
   gets_s(input);
   x=atoi(input);
   return(x);
}

Result


Related Tutorials