c printf int code example
Example 1: how to print int in c
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d", number);
return 0;
}
Example 2: c printf
/* printf example */
int main()
{
printf ("Characters: %c %c \n", 'a', 65);
printf ("Decimals: %d %ld\n", 1977, 650000L);
printf ("Preceding with blanks: %10d \n", 1977);
printf ("Preceding with zeros: %010d \n", 1977);
printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
printf ("Width trick: %*d \n", 5, 10);
printf ("%s \n", "A string");
return 0;
}
Example 3: printf signed char
%c --- char
%hh --- signed char (synomous with char)
%hhu --- unsigned char
%h --- short
%hu --- unsigned short
%d --- int
%u --- unsigned int
%lu --- unsigned long (including size_t, which is returned by sizeof())
Example 4: c print statement
printf("hello");
Example 5: printf c
int main () {
int ch;
for( ch = 75 ; ch <= 100; ch++ ) {
printf("ASCII value = %d, Character = %c\n", ch , ch );
}
return(0);
}