Program Practice Tutorials
By Prof Sukeshini Jadhav
stdio.h – Basic Output
• #include <stdio.h>
• int main() {
• printf("Hello, World!\n");
• return 0;
• }
• stdio.h is used for input/output functions.
• printf displays output on screen.
stdlib.h – Random Numbers
• #include <stdio.h>
• #include <stdlib.h>
• int main() {
• printf("Random number: %d\n", rand());
• return 0;
• }
• stdlib.h provides general utilities.
string.h – String Length
• #include <stdio.h>
• #include <string.h>
• int main() {
• char word[] = "Programming";
• printf("Length of '%s' = %lu\n", word,
strlen(word));
• return 0;
• }
math.h – Square Root
• #include <stdio.h>
• #include <math.h>
• int main() {
• double x = 16.0;
• printf("Square root of %.2f = %.2f\n", x,
sqrt(x));
• return 0;
• }
ctype.h – Character Conversion
• #include <stdio.h>
• #include <ctype.h>
• int main() {
• char c = 'b';
• printf("Original: %c, Uppercase: %c\n", c,
toupper(c));
• return 0;
• }
time.h – Current Time
• #include <stdio.h>
• #include <time.h>
• int main() {
• time_t now = time(NULL);
• printf("Seconds since Jan 1, 1970: %ld\n",
now);
• return 0;
• }
stdbool.h – Boolean Example
• #include <stdio.h>
• #include <stdbool.h>
• int main() {
• bool isOn = true;
• printf("Light status: %d (1 = ON, 0 = OFF)\n",
isOn);
• return 0;
• }
limits.h – Integer Limits
• #include <stdio.h>
• #include <limits.h>
• int main() {
• printf("Max int: %d\n", INT_MAX);
• printf("Min int: %d\n", INT_MIN);
• return 0;
• }
float.h – Floating-Point Limits
• #include <stdio.h>
• #include <float.h>
• int main() {
• printf("Max float: %e\n", FLT_MAX);
• printf("Min float: %e\n", FLT_MIN);
• return 0;
• }
errno.h – Error Example
• #include <stdio.h>
• #include <errno.h>
• #include <math.h>
• int main() {
• errno = 0;
• double result = sqrt(-5);
• printf("Error code (if any): %d\n", errno);
• return 0;