C Language Practice Programs for Beginners with Output

Mastering the C programming language is all about consistent practice and getting your hands dirty with real coding. This guide is packed with a selection of beginner-friendly C programs, each one featuring clear explanations and sample outputs. Whether you're just starting out and trying to wrap your head around the basics or you're looking to solidify your understanding of core concepts, these examples will be great tools for your learning journey.

Blogging Illustration

If you're after a more structured approach and some expert guidance, signing up for a C Programming Course in Noida could be a game changer. Places like Uncodemy offer in-depth courses that mix theory with practical exercises, giving you a well-rounded grasp of C programming.

Basic C Programs

1. Hello World Program

C program example :
#include 
 
int main() {
    printf("Hello, World!\n");
	return 0;
}
Output :

Hello, World!

Explanation

This is the classic beginner program that simply prints "Hello, World!" to the console. It's a great way to get familiar with the syntax and structure of a C program.

2. Print an Integer Entered by the User

C program example :
#include 
 
int main() {
	int number;
	printf("Enter an integer: ");
    scanf("%d", &number);
    printf("You entered: %d\n", number);
	return 0;
}
Output :

Enter an integer: 25

You entered: 25

Explanation :

This program shows you how to capture user input with scanf and then display it using printf.

3. Add Two Numbers

C program example :
#include 
 
int main() {
	int a, b, sum;
    printf("Enter two integers: ");
    scanf("%d %d", &a, &b);
	sum = a + b;
    printf("Sum: %d\n", sum);
	return 0;
}
Output :

Enter two integers: 10 20

Sum: 30

Explanation :

This program adds two integers provided by the user and displays the result.

4. Multiply Two Floating-Point Numbers

C program example :
#include 
 
int main() {
	float a, b, product;
    printf("Enter two numbers: ");
    scanf("%f %f", &a, &b);
	product = a * b;
    printf("Product: %.2f\n", product);
	return 0;
}
Output :

Enter two numbers: 2.5 4.0

Product: 10.00

Explanation :

This program multiplies two floating-point numbers and displays the product with two decimal places.

5. Find ASCII Value of a Character

C program example :
#include 
 
int main() {
	char c;
    printf("Enter a character: ");
    scanf("%c", &c);
	printf("ASCII value of %c = %d\n", c, c);
	return 0;
}
Output :

Enter a character: A

ASCII value of A = 65

Explanation :

This program takes a character input from the user and displays its corresponding ASCII value.

Control Flow Programs

6. Check Whether a Number is Even or Odd

C program example :
#include 
 
int main() {
	int num;
    printf("Enter an integer: ");
    scanf("%d", &num);
	if (num % 2 == 0)
        printf("%d is even.\n", num);
	else
    	printf("%d is odd.\n", num);
	return 0;
}
Output :

Enter an integer: 7

7 is odd.

Explanation :

This program determines if the number you input is even or odd by using the modulo operator.

7. Find the Largest Number Among Three Numbers

C program example :
#include 
 
int main() {
	int a, b, c;
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);
	if (a >= b && a >= c)
        printf("Largest number: %d\n", a);
	else if (b >= a && b >= c)
        printf("Largest number: %d\n", b);
	else
        printf("Largest number: %d\n", c);
	return 0;
}
Output :

Enter three numbers: 10 20 15

Largest number: 20

Explanation :

This program takes three numbers and figures out which one is the biggest.

8. Check Leap Year

C program example :
#include 
 
int main() {
	int year;
    printf("Enter a year: ");
    scanf("%d", &year);
	if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
        printf("%d is a leap year.\n", year);
	else
        printf("%d is not a leap year.\n", year);
	return 0;
}
Output :

Enter a year: 2020

2020 is a leap year.

Explanation :

This program checks whether a given year is a leap year based on the standard rules.

Looping Programs

9. Print All Natural Numbers from 1 to n

C program example :
#include 
 
int main() {
	int n, i;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
	for (i = 1; i <= n; ++i) printf("%d ", i); return 0; } < pre>
                    
Output :

Enter a positive integer: 5

1 2 3 4 5

Explanation :

This program prints all natural numbers from 1 to the user-specified number using a for loop.

10. Calculate the Sum of Natural Numbers

C program example :
#include 
 
int main() {
	int n, i, sum = 0;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
	for (i = 1; i <= n; ++i) sum +="i;" printf("sum='%d\n",' sum); return 0; } < pre>
                    
Output :

Enter a positive integer: 10

Sum = 55

Explanation :

This program calculates the sum of all natural numbers up to the specified number.

11. Display Multiplication Table

C program example :
#include 
 
int main() {
	int n, i;
    printf("Enter an integer: ");
    scanf("%d", &n);
	for (i = 1; i <= 10; ++i) printf("%d x %d='%d\n",' n, i, n * i); return 0; } < pre>
                    
Output :

Enter an integer: 5

5 x 1 = 5

5 x 2 = 10

...

5 x 10 = 50

Explanation :

This program displays the multiplication table of the entered number up to 10.

Array Programs

12. Find the Largest Element in an Array

C program example :
#include 
 
int main() {
	int n, i;
	float arr[100];
    printf("Enter the number of elements (1 to 100): ");
    scanf("%d", &n);
	for (i = 0; i < n; ++i) {
        printf("Enter number%d: ", i + 1);
        scanf("%f", &arr[i]);
	}
	for (i = 1; i < n; ++i) {
    	if (arr[0] < arr[i])
            arr[0] = arr[i];
	}
    printf("Largest element = %.2f\n", arr[0]);
	return 0;
}
Output :

Enter the number of elements (1 to 100): 5

Enter number1: 3.4

Enter number1: 3.4

Enter number2: 2.5

Enter number3: 5.1

Enter number4: 1.2

Enter number5: 4.8

Largest element = 5.10

Explanation :

This program finds the largest element in a user-defined array.

Additional Practice Programs

13. Reverse a Number

C program example :
#include 
 
int main() {
	int num, reversed = 0, remainder;
    printf("Enter an integer: ");
    scanf("%d", &num);
 
	while (num != 0) {
        remainder = num % 10;
    	reversed = reversed * 10 + remainder;
    	num /= 10;
	}
 
    printf("Reversed number = %d", reversed);
	return 0;
}
Output :

Enter an integer: 1234

Reversed number = 4321

Explanation :

This program uses a while loop to extract digits from the number and reverse their order. A great way to learn about loops and modular arithmetic in C.

14. Factorial of a Number Using Function

C program example :
#include 
 
int factorial(int n) {
	if (n == 0)
    	return 1;
	else
    	return n * factorial(n - 1);
}
 
int main() {
	int num;
    printf("Enter a number: ");
    scanf("%d", &num);
    printf("Factorial of %d = %d", num, factorial(num));
	return 0;
}
Output :

Enter a number: 5

Factorial of 5 = 120

Explanation :

This program defines a recursive function to compute the factorial of a number. It’s a solid example to understand recursion and function usage in C.

Understanding the Importance of Dry Run in C Programming

Before you hit that compile button, taking a moment to do a dry run of your program is a smart move, especially if you're just starting out. A dry run involves going through your code manually, line by line, and predicting what each variable will hold or what the outcome will be. This practice not only helps you grasp how the logic flows but also clarifies what each statement does and where you might stumble upon a bug.

By dry running your C programs, you’ll also deepen your grasp of how loops work, how conditionals execute, and how memory is allocated. Many common programming pitfalls—like infinite loops, wrong outputs, or segmentation faults—can be sidestepped simply by tracing through your logic beforehand.

Conclusion

As beginners work through these C language programs, they can solidify their understanding of key concepts such as variables, loops, conditionals, arrays, and functions. Mastering these examples is not just vital for nailing technical interviews; it’s also essential for excelling in academic exams and tackling larger projects.

To speed up your learning journey, think about signing up for the C Programming Course in Noida (uncodemy.com). At Uncodemy, you’ll dive into real-world projects, learn from expert mentors, and receive placement assistance—an ideal launchpad for a career in software development.

FAQs on C Language Practice Programs

Q1. Why should beginners practice basic programs in C?

Ans: Getting hands-on with basic programs is a great way for beginners to sharpen their logical thinking skills, grasp the syntax, and become familiar with essential programming concepts like loops, conditionals, and functions.

Q2. How do arrays help in C programming?

Ans: Arrays are super useful because they let you store multiple values in one variable. This makes it much easier to handle lists and carry out tasks like sorting, searching, and manipulating data efficiently.

Q3. What is recursion in C?

Ans: Recursion happens when a function calls itself to tackle a smaller version of the same problem. It's a popular technique for solving issues like calculating factorials, generating Fibonacci series, and traversing trees.

Q4. Which IDE should I use for running C programs?

Ans: For beginners, Turbo C++, Code::Blocks, or Visual Studio Code with a GCC compiler are great options. If you're on Linux, you can run GCC directly from the terminal.

Q5. Is Uncodemy good for learning C programming?

Ans: Absolutely! Uncodemy provides a well-structured C Programming Course in Noida, complete with practical examples, live projects, interview preparation, and placement support—perfect for beginners and job seekers alike.

Q6. Are these practice programs helpful in cracking interviews?

Ans: Definitely! These programs are excellent for testing your understanding of logic and syntax, which are often key topics in interviews for entry-level programming or developer positions.

Placed Students

Our Clients

Partners

Uncodemy Learning Platform

Uncodemy Free Premium Features

Popular Courses