Professional Documents
Culture Documents
C Program Help
C Program Help
y abbreviated form.
example
int
main(void)
{
printf("Hello, world!\n");
return EXIT_SUCCESS;
}
printf
Function to print to the standard terminal window.
syntax
printf( format string, variable list);
where format string is a string to be printed to the console window. All the cha
racters of the string will be printed except for special combinations that indic
ate special characters or variable formats. For example, \n means line-feed, \t
means tab. Following the format string is the variable list, which may contain a
ny number of variables including no variables. Corresponding to each variable, t
here is a format specifier of the corresponding type and in the corresponding or
der in the format string. For example, %d corresponds to an integer variable, %f
to a floating point variable or a double precision variable. %lf may also be us
ed for double precision. %e or %E corresponds to printing a floating point numbe
r or double precision variable in scientific notation. In addition, the number o
f digits in the number and the number of digits in the fractional part may be sp
ecified, as in %10d or %20.15lf. %-12.6f meaans left-justify in the field and %+
20.8f means always print the sign. Finally %g will print a float or a double eit
her as a decimal fraction or in scientific notation as appropriate.
example
printf("Hello, world!\n");
printf("%6d. The area of a circle whose radius is \t %10.3f is %lf \n", ivar,f
var,dvar);
scanf
Function to take user input from the standard terminal window.
syntax
scanf( format string, list of &variables);
where format string is a string that describes the variable types to be read. Fo
llowing the format string is the list of &variables, which may contain any numbe
r of variables, each preceded by "&". Corresponding to each variable, there is a
format specifier of the corresponding type and in the corresponding order in th
e format string. For example, %d corresponds to an integer variable, %f to a flo
ating point variable and %lf (long float) corresponds to a double precision vari
able. This time, %f must be used only for a floating point variable and %lf must
be used only for a double precision variables. If you are scanf-ing more than o
ne variable, be sure to separate your input variables by white space characters
(space, tab, linefeed) and not by commas.
example
int n;
double x, epsilon;
printf(" Enter the number :");
scanf("%d", &n);
printf(" Please type x and epsilon :\n");
scanf("%lf %lf", &x, &epsilon);
style
It is good practice to print a prompt to remind the user what variable is being
requested.
int, float, double, char &c.
Assigns memory of various types to variable names
syntax