How to Make a Simple C Programs?

Varun Saharawat is a seasoned professional in the fields of SEO and content writing. With a profound knowledge of the intricate aspects of these disciplines, Varun has established himself as a valuable asset in the world of digital marketing and online content creation.

For beginners, the C program is frequently their first option. Practice some of the basic C programs in this article if you want to learn and gain experience with C programming problems.

simple C programs

Many Simple C Programs are asked in interviews and university exams. C Programming language is a high-level general-purpose language that is highly used for developing operating and embedded systems.

It is known as the “Mother of all programming languages” as it forms the basis of derivation of all other programming languages. If you are a beginner looking for a few simple C programs to solve, then read this article.

Table of Contents

Top 20 Simple C Programs for Beginners

Check some of the simple C programs at the beginner level to start your programming journey.

1. Write a Program for taking input from users.

// Taking integer input

printf (“Enter an integer: “);

scanf (“%d”, &integerInput); //Use scanf() to take user input

// Taking floating-point input

printf (“Enter a float: “);

// Taking character input (skipping leading whitespace)

printf (“Enter a character: “);

// Displaying the inputs received

printf (“\nInteger entered: %d\n”, integerInput);

printf (“Float entered: %.2f\n”, floatInput);

printf (“Character entered: %c\n”, charInput);

Output

simple c program

2. Write a Simple C Program to find the ASCII value of a character.

printf(“Enter a character : “);

printf (“\n\nASCII value of given character %c = %d”,c,c);

Output

simple c program

Q3. Write a Simple C program to reverse the case of the input character.

printf(“Enter an alphabet : “);

printf(“\n\nReverse case of %c is : “,alpha);

if(islower(alpha)) //Check if it is in lowercase

printf(“%c”,tolower(alpha)) ; //Convert into lowercase

Output

simple c program

Q4. Write a simple c program to check whether an input is a vowel or not.

We will use Switch cases to check whether the given input is a vowel or not. Check the implementation in the table below.

printf (“Enter any Character : “);

printf(“\n\n%c is a vowel.\n\n”, ch);

printf(“%c is not a vowel.\n\n”, ch);

Output

simple c program

Q5. Write a simple C program to swap two numbers.

We will use a temporary variable to swap the given two numbers. Check the implementation below.

int num1, num2, temp;

// Input the two numbers

printf(“Enter number 1: “);

printf(“Enter number 2: “);

// Display the original numbers

printf(“Number 1: %d\n”, num1);

printf(“Number 2: %d\n”, num2);

// Swap the numbers using a temporary variable

// Display the swapped numbers

printf(“Number 1: %d\n”, num1);

printf(“Number 2: %d\n”, num2);

Output

simple c program

Q6. Write a simple C program to find the factorial of a number using for loop.

long int fact = 1;

printf(“Enter a number of your choice: “);

printf(“Factorial of number %d is %ld”, n , fact);

Output

simple c program

Q7. Write a simple C program to print the Fibonacci series.

void fibonacci(int num);

printf(“Enter the number of terms in the Fibonacci series: “);

fibonacci(num); // Call fibonacci function

void fibonacci(int num)

int a = 0, b = 1, c, i;

Output

simple c program

Q8. Write a simple C program to find the average of N numbers.

float number, sum = 0.0, average;

printf(“Enter the number of elements: “);

// Prompt user to enter N numbers

printf(“Enter %d numbers:\n”, N);

sum += number; // Add each number to the sum

average = sum / N;

printf(“Average of the entered numbers = %.2f\n”, average);

printf(“Cannot calculate average. Number of elements should be greater than zero.\n”);

Output

simple c program

Q9. Write a simple C program to find the factors of a given number.

printf(“Enter any number to find the factors of : “);

printf(“\n\n\nFactors of %d are \n\n”, num);

Output

simple c program

Q10. Write a simple C program to check if a given number is an integer or float.

int length, i = 0;

printf(“\n\nEnter a number: “);

// Keep checking until the end.

printf(“\nEntered Number is a Floating point Number\n”);

printf(“\nEntered Number is a integer Number\n”);

Output

simple c program

Q11. Write a simple C program to reverse an array.

// Function to swap two integers

void swap(int *a, int *b)

// Function to reverse an array

void reverseArray(int arr[], int size)

int end = size – 1;

// Swap elements at start and end indices

// Move start index forward

// Move end index backward

void printArray(int arr[], int size)

int arr[100]; // Assuming maximum size of array is 100

// Input the size of the array

printf(“Enter the size of the array: “);

// Input the elements of the array

printf(“Enter %d elements:\n”, size);

// Reverse the array

// Print the reversed array

Output

simple c program

Q12. Write a simple C program to insert an element in an array.

int array[], position, c, n, value;

printf(“\nEnter total number of elements in array:”);

printf(“\n\nEnter %d elements\n”, n);

printf(“\n\nEnter the location where you want to insert the new element: “);

printf(“\n\nEnter the value to insert: “);

// Shift the elements to right

for(c = n-1; c >= position-1; c–)

array[position – 1] = value; // insert the value

printf(“\n\nResultant array is: “);

Output

simple c program

Q13. Write a simple C Program to remove duplicates from a sorted array.

int remove_duplicate(int arr[], int n)

if (arr[i] != arr[i + 1])

printf(“Enter the size of array: “);

printf(“\n Original Array Before Removing Duplicates: “);

n = remove_duplicate(arr, n);

printf(“\nArray After Removing Duplicates: “);

Output

simple c program

Q14. Write a simple C program to print the sum of n numbers.

int n, sum = 0, i, array[100];

printf(“Enter the number of integers to add: “);

printf(“\n\nEnter %d integers \n\n”, n);

sum += array[i]; // same as sum = sum + array[c]

printf(“\n\nSum = %d\n\n”, sum);

Output

simple c program

Q15. Write a simple C program to find palindrome using recursion.

// Function to check if a character is a valid alphabet letter

int isAlphabet(char ch)

// Function to convert a character to lowercase

char toLower(char ch)

return ch + (‘a’ – ‘A’);

// Recursive function to check if a string is a palindrome

int isPalindrome(char str[], int left, int right)

// Base case: if the left index is greater than or equal to the right index

return 1; // It’s a palindrome

// Ignore non-alphabet characters and move to the next character

return isPalindrome(str, left + 1, right);

return isPalindrome(str, left, right – 1);

// Convert characters to lowercase for case-insensitive comparison

char leftChar = toLower(str[left]);

char rightChar = toLower(str[right]);

if (leftChar == rightChar)

return isPalindrome(str, left + 1, right – 1);

return 0; // Not a palindrome

printf(“Enter a string: “);

fgets(str, sizeof(str), stdin);

// Remove newline character if present in the string

str[strcspn(str, “\n”)] = ‘\0’;

int len = strlen(str);

int result = isPalindrome(str, 0, len – 1);

printf(“‘%s’ is a palindrome.\n”, str);

printf(“‘%s’ is not a palindrome.\n”, str);

Output

simple c program

Q16. Write a simple program to find largest element in an array.

int findLargest(int arr[], int size)

int maxRest = findLargest(arr + 1, size – 1);

return (arr[0] > maxRest) ? arr[0] : maxRest;

printf(“Enter the size of the array: “);

printf(“Enter %d elements:\n”, size);

int largest = findLargest(arr, size); //Calling the function recursively

printf(“The largest element in the given array is: %d\n”, largest);

Output

simple c program

Q17. Write a simple C program to Find the LCM of two given numbers.

int gcd(int a, int b)

//Function to calculate LCM of two given number.

int lcm(int a, int b)

// Use the formula: LCM(a, b) = (|a * b|) / GCD(a, b)

int gcd_value = gcd(abs_a, abs_b);

int lcm_value = (abs_a * abs_b) / gcd_value;

// Input two numbers from the user

printf(“Enter first number: “);

printf(“Enter second number: “);

// Calculate the LCM of the two numbers

int result = lcm(num1, num2);

// Display the LCM

printf(“LCM of %d and %d is: %d\n”, num1, num2, result);

Output

simple c program

Q18. Write a simple C program to add two numbers using recursion.

// Recursive function to add two numbers

int add(int a, int b)

// Base case: if the second number is 0, return the first number

// Recursive case: add one to the first number and decrement the second number

return add(a + 1, b – 1);

printf(“Enter first number: “);

printf(“Enter second number: “);

int sum = add(num1, num2); //Call the function recursively

// Display the result

printf(“Sum of %d and %d is: %d\n”, num1, num2, sum);

Output

simple c program

Q19. Write a simple C program to check input numbers for odd and even.

printf(“Enter a number: “);

printf(“%d is even.\n”, number);

printf(“%d is odd.\n”, number);

Output

simple c program

Q20. Write a simple C program to find the area of a triangle using the base and height.

float base, height, area;

//Enter the base and height of triangle

printf(“Enter the base of the triangle: “);

printf(“Enter the height of the triangle: “);

area = 0.5 * base * height;

printf(“The area of the triangle with base %.2f and height %.2f is: %.2f\n”, base, height, area);

Output

simple c program

Learn DSA with C++, Java, Python

Enroll in our decode DSA C++ Course with popular languages like Python, C++ and Java to master coding along with data structure and algorithm. Get seamless support during the course with doubt session support, career guidance, and more. Hurry learn from the best only at pwskills.com.

Simple C Programs FAQs

What are simple programs in C?

Some of the simple C programs are Hello World, addition, ASCII value, factorial, palindrome and more. Check out this article.

What is %d in C programming?

%d is a format specifier in C language to take integers as input and is used mainly with printf() and scanf() functions.

What is getch() in C programming?

getch() is used to get a single character from the user as an input.

Must Read

C Program To Check Leap Year – How to Find

By Ankit kumar / September 11, 2024

c program to check leap year

Let us write a C program to check leap year. We are using If and Else statements to find whether…

C Plus Plus Tutorial: Class, Objects, Applications

By Varun Saharawat / September 4, 2024

c plus plus

C Plus Plus: Welcome to the exciting world of C Plus Plus programming! In this course, you'll embark on a journey…

What Is the Meaning Of 1LL In C++?

By Varun Saharawat / September 4, 2024

1ll in c++

1LL In C++ denotes a literal constant of type "long long", representing the integer value 1. It's commonly used to…

Telegram Group Join Now WhatsApp Channel Join Now YouTube Channel Subscribe

right adv

Related Articles

Recent Posts

Product Director Jobs

Product Director Jobs are responsible for managing and supervising the development team throughout the product development process.

c program to check leap year

Let us write a C program to check leap year. We are using If and Else statements to find whether a given year is a leap year or not.

HTML Programming is a basic markup language used to structure the layout of the web pages. With HTML browser get to know how to display different elements and components on the web page.

Python Basics Internships

These Top 5 Python Basics Internships will help you to boost your career to the next level by providing you with the relevant experience and knowledge.

free internships

Grab free internships for freshers with Google, Infosys, Accenture, IITs, and top institutions for free. Work on real-world projects, upskill, and boost your productivity with hands-on experience with internship programs.

Data Science Course

Top data science courses In IIMs include- 1. Senior Management Programme in Business Analytics - IIM Calcutta, 2. Business Analytics Programme - IIM Bangalore and much more.