Examples of C: Simple C Programs for Beginners (With Output)

Examples of C help beginners learn C programming fast. This guide includes simple C programs, basic C codes, practice questions, and real outputs. Use these examples to understand logic, syntax, loops, functions, and problem-solving — all designed for step-by-step learning through clear, tested C program examples.
authorImageVarun Saharawat30 Oct, 2025
Examples of C: Simple C Programs for Beginners (With Output)

Examples of C: Are you just starting out in C programming but feeling overwhelmed? Maybe you’ve been working through the basics of C programming for a while, but are now looking to take your skills to the next level. If so, we can definitely relate!

Here, we share C programs covering various topics in C Programming, including arrays, strings, series, area & volume of geometrical figures, mathematical calculations, sorting & searching algorithms, and many more. Our goal is to provide comprehensive solutions to all C programming questions you may encounter, whether in interviews or class assignments. 

Each program in this article is accompanied by its working code and output. The programs are organized into categories, with related programs grouped together. It is recommended to grasp the fundamentals of the C language through our C tutorial before delving into these C programs. You can also download our C programming examples PDF to get instant access to C programming examples. So, whether you're just setting out or have already made some progress in your learning adventure, this will be the perfect resource guide for honing your C coding skills!

If you find learning C language challenging, consider exploring our new C course from Physics Wallah. This interactive learning experience involves understanding a concept, completing small coding exercises, and progressing to the next lesson.

Basic Programs in C

Basic programs in C help beginners understand structure, syntax, and logic flow. These foundational examples teach how main(), variables, data types, operators, and input/output functions work. By practicing these basic C programs, you build the confidence needed to write more complex code using loops, functions, arrays, and conditions.

Basic C Program Example

Here’s a simple and clean basic C program example that shows how a C program is structured. This example includes headers, the main() function, variable declaration, and printing output — making it ideal for absolute beginners.

Example: Print “Hello, World!”

#include <stdio.h> int main() { printf("Hello, World!"); return 0; }

Explanation

  • #include <stdio.h> loads standard input/output functions.
  • main() marks the program’s starting point.
  • printf() displays text on the screen.
  • return 0; signals successful execution.
  • This basic C program example is the first step toward writing more advanced logic.

Basic C Program Code

Below is another basic C program code example that takes user input, performs a simple operation, and prints output. It helps beginners understand variables, input handling, and arithmetic operations.

Example: Add Two Numbers

#include <stdio.h> int main() { int a, b, sum; printf("Enter two numbers: "); scanf("%d %d", &a, &b); sum = a + b; printf("Sum = %d", sum); return 0; }

Explanation

  • int a, b, sum; → declares integer variables.

  • scanf() → takes input from the user.

  • sum = a + b; → performs arithmetic.

  • printf() → prints the result.

This basic C program code teaches input/output operations and arithmetic — a key skill for beginners.

Simple C Programs for Beginners

Simple C programs help beginners understand logic without feeling overwhelmed. These examples focus on input/output, basic calculations, conditions, and loops. Practicing these simple C programs builds confidence and prepares you for larger concepts like arrays, functions, and structures.

Simple C Program With Output

Below is a simple C program with output to help beginners see how code behaves during execution.

Example: Check If a Number Is Even or Odd

#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num % 2 == 0) { printf("%d is Even", num); } else { printf("%d is Odd", num); } return 0; }

Output

Enter a number: 7 7 is Odd

Why This Helps Beginners

  • Introduces if-else

  • Teaches modulus operator %

  • Shows simple decision-making in C

  • Provides clear output for verification

This snippet is ideal for users searching for a simple C program with output.

Simple C Codes for Practice

Here are more simple C codes to help beginners practice essential concepts like loops and characters.

1. Print Numbers From 1 to 10

#include <stdio.h> int main() { for (int i = 1; i <= 10; i++) { printf("%d ", i); } return 0; } What You Learn
  • Looping (for loop)
  • Increment operations
  • Printing sequences
2. Print Alphabets From A to Z#include <stdio.h> int main() { for (char c = 'A'; c <= 'Z'; c++) { printf("%c ", c); } return 0; } What You Learn
  • Character iteration
  • ASCII sequence
  • Loop fundamentals
3. Simple Program to Find Square of a Number #include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); printf("Square = %d", num * num); return 0; } What You Learn
  • User input
  • Arithmetic operations
  • Printing results

These simple C codes give beginners hands-on practice and strengthen logical thinking.

C Programs for Beginners

C programs for beginners focus on simple logic, clear syntax, and foundational concepts. These beginner-friendly examples help you understand variables, input/output functions, operators, loops, and control flow. Practicing these C programs builds confidence and prepares you to solve real coding problems step-by-step.

Beginner C Programs List

Here is a quick list of beginner C programs that every student should practice first. These programs strengthen basics through hands-on execution.

1. Program to Add Two Numbers

#include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); printf("Sum = %d", a + b); return 0; } You learn: input, variables, arithmetic. 2. Program to Find Maximum of Two Numbers #include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); if (a > b) printf("%d is greater", a); else printf("%d is greater", b); return 0; }

You learn: if-else, comparison.

3. Program to Check if Number is Positive or Negative

#include <stdio.h> int main() { int n; printf("Enter a number: "); scanf("%d", &n); if (n > 0) printf("Positive"); else if (n < 0) printf("Negative"); else printf("Zero"); return 0; } You learn: nested conditions.

These beginner C programs help students quickly build comfort with syntax and logic.

C Programming Basics Program

This section includes a C programming basics program that teaches the core structure used in almost every C program: input, processing, and output.

Example: Calculate the Area of a Rectangle

#include <stdio.h> int main() { float length, width, area; printf("Enter length and width: "); scanf("%f %f", &length, &width); area = length * width; printf("Area = %.2f", area); return 0; }

Why This Program Is Important

  • Uses float variables
  • Demonstrates basic formula application
  • Shows formatted output (%.2f)
  • Strengthens problem-solving foundation
Another Basics Program: Simple Interest Calculation #include <stdio.h> int main() { float p, r, t, si; printf("Enter principal, rate, and time: "); scanf("%f %f %f", &p, &r, &t); si = (p * r * t) / 100; printf("Simple Interest = %.2f", si); return 0; }

What You Learn

  • Mathematical operations
  • Real-world formula implementation
  • User input/output formatting

These C programming basics programs help beginners understand how to structure calculations and handle inputs, which are essential in early coding practice.

C Program Examples for Practice

C program examples for practice help you move beyond basic syntax and start applying logic. These programs strengthen your understanding of loops, conditions, arithmetic operations, and user input. Practicing these C programs regularly improves problem-solving skills and prepares you for assignments, tests, and coding interviews.

Some C Programs for Practice

Below are some C programs for practice that cover essential concepts like loops, logic, conditions, and functions.

1. Program to Print the Sum of First N Natural Numbers

#include <stdio.h> int main() { int n, sum = 0; printf("Enter value of n: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { sum += i; } printf("Sum = %d", sum); return 0; }

What You Learn: loops, accumulation logic, basic math.

2. Program to Reverse a Number

#include <stdio.h> int main() { int num, rev = 0, digit; printf("Enter a number: "); scanf("%d", &num); while (num > 0) { digit = num % 10; rev = rev * 10 + digit; num /= 10; } printf("Reversed Number = %d", rev); return 0; }

What You Learn: modulo operator, loop logic, number manipulation.

3. Program to Count Digits in a Number

#include <stdio.h> int main() { int num, count = 0; printf("Enter a number: "); scanf("%d", &num); while (num != 0) { num /= 10; count++; } printf("Number of digits = %d", count); return 0; }

What You Learn: loops, integer division, logic reasoning.

These C programs for practice build analytical thinking and help you apply C concepts effectively.

C Program Exercises (With Solutions)

Here are a few C program exercises with solutions that challenge beginners to write clean and correct code. Exercise 1: Find the Factorial of a Number #include <stdio.h> int main() { int n; unsigned long long fact = 1; printf("Enter a number: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { fact *= i; } printf("Factorial = %llu", fact); return 0; }

Concepts: loops, large number handling, multiplication logic.

Exercise 2: Check if a Number is a Palindrome

#include <stdio.h> int main() { int num, original, rev = 0; printf("Enter a number: "); scanf("%d", &num); original = num; while (num > 0) { rev = rev * 10 + (num % 10); num /= 10; } if (original == rev) printf("Palindrome"); else printf("Not Palindrome"); return 0; }

Concepts: number reversal, conditional statements, comparison.

Exercise 3: Find the Greatest Among Three Numbers

#include <stdio.h> int main() { int a, b, c; printf("Enter three numbers: "); scanf("%d %d %d", &a, &b, &c); if (a >= b && a >= c) printf("%d is greatest", a); else if (b >= a && b >= c) printf("%d is greatest", b); else printf("%d is greatest", c); return 0; }

Concepts: nested conditions, comparison operators.

These C program exercises with solutions help beginners test their understanding and build confidence through problem-solving practice.

C Programming Examples With Output

C programming examples with output help beginners understand exactly how code works during execution. Seeing both the program and its expected output makes learning faster, reduces confusion, and builds confidence. These examples focus on simple logic, conditions, loops, and input/output — perfect for hands-on practice.

Example 1: Check Whether a Number is Positive, Negative, or Zero

(Supports: “c programming examples with output”, “c simple program with output”)

#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num > 0) printf("Positive"); else if (num < 0) printf("Negative"); else printf("Zero"); return 0; }

Output

Enter a number: 5 Positive

What You Learn: conditions, comparison operators, simple decision-making.

Example 2: Check Whether a Number is Even or Odd

#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (num % 2 == 0) printf("Even"); else printf("Odd"); return 0; }

Output

Enter a number: 12 Even

What You Learn: modulo operator, logic building.

Example 3: Calculate Sum of Natural Numbers

#include <stdio.h> int main() { int n, sum = 0; printf("Enter n: "); scanf("%d", &n); for (int i = 1; i <= n; i++) { sum += i; } printf("Sum = %d", sum); return 0; }

Output

Enter n: 5 Sum = 15 What You Learn: loops, arithmetic progression. Example 4: Print Alphabets From A to Z #include <stdio.h> int main() { for (char c = 'A'; c <= 'Z'; c++) { printf("%c ", c); } return 0; }

Output

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

What You Learn: character iteration, ASCII concepts, loop practice.

C Programming Examples With Output PDF

If you prefer learning offline, you can download a C Programming Examples With Output PDF that includes:

  • Basic C programs

  • Simple logic programs

  • Loop-based examples

  • Condition-based examples

  • Beginner exercises with solutions

  • Ready-to-run code snippets

This makes it easy to practice C anytime without needing an internet connection.

“Download the complete C programming examples with output PDF to practice beginner-friendly programs with ready-made solutions.”

Basic C Programs for Practice (PDF Available)

Basic C programs for practice help beginners strengthen their fundamentals through hands-on coding. These programs cover variables, input/output, loops, and simple logic — all essential for building a strong foundation in C. If you're preparing for exams or assignments, these beginner-friendly examples will speed up your learning.

Additionally, you can download basic C programs for beginners (PDF) to practice offline with ready-made solutions.

C Programs Examples PDF

The C program examples PDF includes a complete collection of easy-to-run programs with explanations and output. It’s useful for revision, quick practice, and offline study.

Below are a few sample programs included inside the PDF.

1. Program to Multiply Two Floating-Point Numbers

#include <stdio.h> int main() { float a, b; printf("Enter two numbers: "); scanf("%f %f", &a, &b); printf("Product = %.2f", a * b); return 0; }

Concepts: float variables, arithmetic operations, formatted output.

2. Program to Find ASCII Value of a Character

#include <stdio.h> int main() { char c; printf("Enter a character: "); scanf("%c", &c); printf("ASCII value of %c = %d", c, c); return 0; }

Concepts: character input, ASCII conversion.

3. Program to Swap Two Numbers

#include <stdio.h> int main() { int a, b, temp; printf("Enter two numbers: "); scanf("%d %d", &a, &b); temp = a; a = b; b = temp; printf("After swap: a = %d, b = %d", a, b); return 0; }

Concepts: variable swapping, temp variable usage.

4. Program to Convert Fahrenheit to Celsius

#include <stdio.h> int main() { float f, c; printf("Enter temperature in Fahrenheit: "); scanf("%f", &f); c = (f - 32) * 5 / 9; printf("Celsius = %.2f", c); return 0; }

Concepts: simple formula application, temperature conversion.

You can download the complete C program examples PDF containing 50+ beginner programs with clean code, logic explanations, and output screenshots for offline practice.

C Codes & Code Examples

C codes and code examples help beginners understand how real programs are structured and executed. These examples focus on simple logic, clean syntax, input/output handling, and basic operations. Practicing these C code examples improves your understanding of variables, loops, conditions, and functions — the core building blocks of C programming.

C Language Codes for Beginners

Below are some easy and essential C language codes for beginners. Each example is simple, practical, and helps you understand a different programming concept. 1. C Code Example: Find the Square of a Number #include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", &num); printf("Square = %d", num * num); return 0; }

Concepts Learned: arithmetic operations, user input, expression evaluation.

2. C Code Example: Calculate Simple Interest

#include <stdio.h> int main() { float p, r, t, si; printf("Enter principal, rate, and time: "); scanf("%f %f %f", &p, &r, &t); si = (p * r * t) / 100; printf("Simple Interest = %.2f", si); return 0; }

Concepts Learned: formulas, float variables, basic finance calculation.

3. C Code Example: Find the Largest of Two Numbers

#include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); if (a > b) printf("%d is largest", a); else printf("%d is largest", b); return 0; }

Concepts Learned: comparison operators, branching logic (if-else).

4. C Code Example: Print First 10 Natural Numbers

#include <stdio.h> int main() { for (int i = 1; i <= 10; i++) { printf("%d ", i); } return 0; }

Concepts Learned: for loops, iteration, printing sequences.

These beginner-friendly C language codes give students hands-on practice in writing clean, error-free C programs. They build the foundation needed for more advanced topics like arrays, pointers, and functions.

C Language Keywords (Beginner Reference)

C language keywords are reserved words that have special meaning in the compiler. You cannot use them as variable names or identifiers. These keywords define the structure, flow, and behavior of a C program. Understanding C keywords helps beginners write correct, error-free code and build strong programming fundamentals.

List of Keywords in C

Below is the complete list of keywords in C (as per the C standard). Each keyword serves a specific purpose, such as data type definition, flow control, memory handling, or program structure.

Keywords in C (Total 32)

1. Data Type Keywords

int float double char void

2. Storage Class Keywords

auto extern register static

3. Control Flow Keywords

if else switch case default for while do goto break continue return
4. Type Modifiers
short long signed unsigned
5. Structure/Union/Enum Keywords
struct union enum
6. Other Core Keywords
const sizeof volatile typedef

💡 What Beginners Should Know (SEO + Context Building)

  • Keywords are fixed and cannot be changed.
  • They tell the compiler how to interpret your code.
  • Using a keyword as a variable name will cause a compilation error.
  • Learning these keywords is essential for writing valid C programs.

These explanations satisfy the intent behind “c keywords and their uses” in a natural, semantic way.

C Programming Questions for Beginners

C programming questions for beginners help new learners test their understanding of variables, loops, conditions, functions, operators, and basic logic building. These beginner-focused questions are ideal for practice, viva preparation, assignments, and coding tests. Each question is simple, conceptual, and designed to strengthen problem-solving skills.

Simple C Programming Questions

Below are some simple C programming questions that help beginners validate their core knowledge. These questions focus on fundamentals and require clear understanding of syntax and logic. 📌 Beginner-Level C Programming Questions
  • Write a C program to print “Hello World”.
  • Write a program to take two numbers as input and display their sum.
  • Write a C program to check whether a number is even or odd.
  • Write a program to find the largest of two numbers.
  • Write a program to calculate the factorial of a given number.
  • Write a C program to reverse a number (e.g., 123 → 321).
  • Write a program to print the first 10 natural numbers.
  • Write a program to check whether a character is a vowel or consonant.
  • Write a C program to find the sum of digits of a number.
  • Write a program to check whether a number is a palindrome.

📌 Conceptual C Questions (Perfect for Interviews & Viva)

  • What is the difference between printf() and scanf()?
  • What are keywords in C? Can you name any five?
  • What is the use of the sizeof operator?
  • What is the difference between while and do-while loops?
  • What is a variable? Why do we need it in C?
  • What is the purpose of return 0; in the main() function?
  • What is the difference between =, ==, and != operators?
  • What is a data type? Name the basic data types in C.
  • What does the break statement do inside a loop?
  • What is the difference between local and global variables?

Why These Questions Matter

These basic C program questions help beginners understand essential concepts such as loops, operators, conditional statements, and input/output handling. Practicing them builds confidence and prepares you for more advanced C programming topics like arrays, strings, and pointers.

Why Practice C Programming Examples?

Practicing examples of C programming is one of the fastest ways to build confidence and master the language. C is a foundational programming language, and every example you practice helps you understand how real programs work — from variables and loops to conditions, functions, and memory handling.

Beginners often learn faster when they see code and run it themselves. Working through C programming examples strengthens problem-solving skills, improves logical thinking, and prepares you for exams, interviews, and real-world development.

Benefits of Practicing C Programming Examples

1. Strengthens Core Programming Concepts

By writing and running examples of C programming, you learn how variables, loops, operators, and conditional statements work in real scenarios.

2. Helps You Understand Program Flow

Seeing step-by-step output teaches how the compiler reads and executes instructions.

3. Builds Logic & Problem-Solving Skills

Each example forces you to think logically — essential for coding interviews and assignments.

4. Prepares Beginners for Advanced Topics

After mastering basic examples, you can easily move to arrays, strings, pointers, and functions.

5. Improves Accuracy & Reduces Errors

Hands-on practice helps identify syntax mistakes, runtime errors, and logical bugs early.

6. Enhances Speed in Writing Programs

The more examples you practice, the faster you become at thinking and coding efficiently.

Quick Reminder for Students

If you are just starting, begin with simple examples of C programming like printing numbers, using operators, or checking conditions. Gradually move to more complex tasks such as recursion, arrays, and pattern programs.

FAQs

What is the purpose of practicing C programming examples?

Practicing C programming examples improves problem-solving, logic building, and code understanding. It teaches syntax, control flow, memory handling, and debugging. Regular practice helps you confidently write your own programs and prepares you for technical interviews and real-world development.

What is a simple C program example?

A simple C program example is the classic “Hello World” code. It introduces basic syntax like #include, main(), and printf(). These programs help beginners understand how compilation, execution, and output work in C.

Where can I find C programming examples with output?

You can find C programming examples with output in this article, C textbooks, GitHub repositories, and learning websites like PW Skills, tutorial portals, and open-source coding platforms. Outputs help you verify your logic and compare expected results.

How can beginners practice C programs effectively?

Beginners should practice C programs daily, starting from simple logic-based programs and moving to loops, arrays, functions, and strings. Rewriting the same program in different ways deepens understanding and boosts coding confidence.

Can I modify basic C programs to create new programs?

Yes, modifying basic C programs is one of the best ways to learn. Changing inputs, adding conditions, or expanding logic helps you understand how C statements interact and prepares you for writing original programs.