Skip to content

code2care/1000-plus-c-programs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

1000-plus-c-programs

A collection of 1000+ C Programs to Learn from for CS and MS Students.

All Code Examples can be downloaded in txt/pdf/doc/md formats.

Program Description Description Sample Input Sample Output Code
Find Sum of two numbers This program takes two numbers as input and calculates their sum. Enter two numbers: 5 7 Sum: 12 View Code
Find Difference of two numbers This program takes two numbers as input and calculates their difference. Enter two numbers: 10 3 Difference: 7 View Code
Divide two numbers This program takes two numbers as input and calculates the result of their division. Enter two numbers: 20 4 Result: 5 View Code
Calculate Area and Circumference of Circle This program calculates the area and circumference of a circle given its radius. Enter radius: 5 Area: 78.54, Circumference: 31.42 View Code
Calculate Area of Square This program calculates the area of a square given its side length. Enter side length: 4 Area: 16 View Code
Calculate Area of Rectangle This program calculates the area of a rectangle given its length and width. Enter length and width: 5 3 Area: 15 View Code
Calculate Area of Parallelogram This program calculates the area of a parallelogram given its base and height. Enter base and height: 6 4 Area: 24 View Code
Calculate Area of Trapezoid This program calculates the area of a trapezoid given its bases and height. Enter a, b, and height: 3 5 4 Area: 16 View Code
Calculate Volume of Cube This program calculates the volume of a cube given its side length. Enter side length: 3 Volume: 27 View Code
Calculate Volume of Cylinder This program calculates the volume of a cylinder given its radius and height. Enter radius and height: 3 5 Volume: 141.37 View Code
Calculate Area of Ellipse This program calculates the area of an ellipse given its semi-major and semi-minor axes. Enter semi-major and semi-minor axes: 5 3 Area: 47.12 View Code
Calculate Volume of Pyramid This program calculates the volume of a pyramid given its base length, width, and height. Enter base length, width, and height: 4 3 6 Volume: 24 View Code
Calculate Volume of Cone This program calculates the volume of a cone given its radius and height. Enter radius and height: 3 4 Volume: 37.70 View Code
Calculate Volume of Sphere This program calculates the volume of a sphere given its radius. Enter radius: 4 Volume: 268.08 View Code
Calculate Volume of Ellipsoid This program calculates the volume of an ellipsoid given its semi-axes. Enter a, b, and c: 3 4 5 Volume: 251.33 View Code
Calculate Surface Area of Cube This program calculates the surface area of a cube given its side length. Enter side length: 4 Surface Area: 96 View Code
Calculate Surface Area of Sphere This program calculates the surface area of a sphere given its radius. Enter radius: 5 Surface Area: 314.16 View Code
Print Multiplication Tables This program prints the multiplication table for a given number. Enter a number: 5 5 x 1 = 5, 5 x 2 = 10, ... View Code
Compute Simple Interest (SI) This program calculates simple interest based on principal, rate, and time. Enter principal, rate, time: 1000 5 2 Simple Interest: 100 View Code
Convert Degree to Fahrenheit This program converts temperature from Celsius to Fahrenheit. Enter temperature in Celsius: 25 Fahrenheit: 77 View Code
Convert Fahrenheit to Degree This program converts temperature from Fahrenheit to Celsius. Enter temperature in Fahrenheit: 77 Celsius: 25 View Code
Convert Meters to Feet This program converts length from meters to feet. Enter length in meters: 5 Feet: 16.40 View Code
Convert Feet to Meters This program converts length from feet to meters. Enter length in feet: 16.40 Meters: 5 View Code
Convert Feet to Centimeters This program converts length from feet to centimeters. Enter length in feet: 5 Centimeters: 152.4 View Code
Convert Feet to Millimeter This program converts length from feet to millimeters. Enter length in feet: 1 Millimeters: 304.8 View Code
Convert Kilometer (Km) to Miles (Mi) This program converts distance from kilometers to miles. Enter distance in km: 10 Miles: 6.21 View Code
Convert Yard to Foot This program converts length from yards to feet. Enter length in yards: 5 Feet: 15 View Code
Convert Inch to Cm This program converts length from inches to centimeters. Enter length in inches: 10 Centimeters: 25.4 View Code
Convert Kb to Mb This program converts file size from kilobytes to megabytes. Enter size in KB: 1024 MB: 1 View Code
Convert Gb to Mb This program converts file size from gigabytes to megabytes. Enter size in GB: 1 MB: 1024 View Code
Convert Mb to Kb This program converts file size from megabytes to kilobytes. Enter size in MB: 1 KB: 1024 View Code
Convert Kg to lbs This program converts weight from kilograms to pounds. Enter weight in kg: 5 Pounds: 11.02 View Code
Convert Kg to Ounce This program converts weight from kilograms to ounces. Enter weight in kg: 1 Ounces: 35.27 View Code
Convert Pounds to Grams This program converts weight from pounds to grams. Enter weight in pounds: 1 Grams: 453.59 View Code
Calculate Total Marks and Percentage This program calculates total marks and percentage from marks of 5 subjects. Enter marks for 5 subjects: 80 75 90 85 70 Total: 400, Percentage: 80% View Code
Calculate Discount Amount This program calculates the discount amount based on price and discount percentage. Enter price and discount %: 100 20 Discount amount: 20 View Code
Swap Two Numbers Using Temporary Variable This program swaps two numbers using a temporary variable. Enter two numbers: 5 10 After swap: 10 5 View Code
Swap Two Numbers Without Using Temporary Variable This program swaps two numbers without using a temporary variable. Enter two numbers: 5 10 After swap: 10 5 View Code
Reverse Digits of Entered Number This program reverses the digits of the entered number. Enter a number: 1234 Reversed: 4321 View Code
Calculate Sum of Digits of Entered Number This program calculates the sum of digits of the entered number. Enter a number: 1234 Sum of digits: 10 View Code
Count Number of Digits This program counts the number of digits in the entered number. Enter a number: 12345 Number of digits: 5 View Code
Find Greatest Among 3 Numbers This program finds the greatest among three entered numbers. Enter three numbers: 10 5 8 Greatest: 10 View Code
Find Smallest Among 3 Numbers This program finds the smallest among three entered numbers. Enter three numbers: 10 5 8 Smallest: 5 View Code
Find if Number is Even or Odd This program checks if the entered number is even or odd. Enter a number: 7 Number is odd View Code
Check if Entered Character is a Vowel or Consonant This program checks if the entered character is a vowel or consonant. Enter a character: a Character is a vowel View Code
Check if Entered Number is a Leap Year This program checks if the entered year is a leap year. Enter a year: 2020 2020 is a leap year View Code
Find Factorial of a Number This program calculates the factorial of the entered number. Enter a number: 5 Factorial: 120 View Code
Display Day of Week Using Switch Case This program displays the day of the week based on the entered day number. Enter day number (1-7): 3 Wednesday View Code
Check if Entered Number is Positive or Negative This program checks if the entered number is positive or negative. Enter a number: -5 Number is negative View Code
Print Individual Digits of Entered Number This program prints the individual digits of the entered number. Enter a number: 1234 Digits: 1 2 3 4 View Code
Find Greatest Among 2 Numbers Using Ternary Operator This program finds the greatest among two entered numbers using a ternary operator. Enter two numbers: 8 5 Greatest: 8 View Code
Display First 10 Natural Numbers and Their Sum This program displays the first 10 natural numbers and their sum. (No input required) Numbers: 1 2 3 4 5 6 7 8 9 10, Sum: 55 View Code
Display star/asterisk triangle sequence 1 This program displays a triangle of asterisks. Enter number of rows: 5


****
*****
View Code
Display star/asterisk triangle sequence 2 This program displays a right-angled triangle of asterisks. Enter number of rows: 5 ***
*


*
View Code
Display star/asterisk triangle sequence 3 This program displays an inverted triangle of asterisks. Enter number of rows: 5 ***
*


*
View Code
Display star/asterisk isoceles triangle/pyramid sequence 4 This program displays an isosceles triangle of asterisks. Enter number of rows: 5 *
***
*****
*******
*********
View Code
Display star/asterisk inverted triangle/pyramid sequence 5 This program displays an inverted isosceles triangle of asterisks. Enter number of rows: 5 *********
********
*******
******
*****
View Code
Display half triangle/pyramid of number sequence 6 This program displays a half pyramid of numbers. Enter number of rows: 5 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
View Code
Display half triangle/pyramid of alphabets sequence 7 This program displays a half pyramid of alphabets. Enter number of rows: 5 A
A B
A B C
A B C D
A B C D E
View Code
Display Pascal Triangle (Pyramid) sequence 8 This program displays Pascal's triangle. Enter number of rows: 5 1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
View Code
Display diamond shape sequence 9 This program displays a diamond shape of asterisks. Enter number of rows: 5 *
***
*****
***
*
View Code
Display diamond shape sequence 10 This program displays a Christmas tree shape of asterisks. Enter number of rows: 5 *
***
*****
*******
*********
View Code
Display triangle on numbers 1 to 15 sequence 11 This program displays a triangle of numbers from 1 to 15. Enter number of rows: 5 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
View Code
Display Fibonacci numbers between 1-100 This program displays Fibonacci numbers between 1 and 100. N/A 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 View Code
Display Fibonacci numbers between 1-100 using recursion function This program displays Fibonacci numbers using recursion. N/A 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 View Code
Print even numbers 2 4 6 8 10 ... This program prints even numbers up to a specified limit. Enter limit: 10 2, 4, 6, 8, 10 View Code
Print odd numbers 1 3 5 7 9 ... This program prints odd numbers up to a specified limit. Enter limit: 10 1, 3, 5, 7, 9 View Code
Sum of series 1 + 1/2 + 1/3 + 1/4 + .... + 1/n This program calculates the sum of the series. Enter n: 4 Sum: 2.0833 View Code
Sum of series 1 + 2 + 3 + 4 + .... + n This program calculates the sum of the first n natural numbers. Enter n: 4 Sum: 10 View Code
Sum of series 2 + 4 + 6 + 8 + .... + n This program calculates the sum of even numbers up to n. Enter n: 10 Sum: 30 View Code
Find square root of a number This program finds the square root of a given number. Enter number: 16 Square root: 4 View Code
Find cube root of a number This program finds the cube root of a given number. Enter number: 27 Cube root: 3 View Code
Add 10 numbers using array This program adds 10 numbers using an array. Enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Sum: 55 View Code
Find max of 10 numbers using array This program finds the maximum of 10 numbers using an array. Enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Max: 10 View Code
Find min of 10 numbers using array This program finds the minimum of 10 numbers using an array. Enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Min: 1 View Code
Find average of 10 numbers using array This program calculates the average of 10 numbers using an array. Enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Average: 5.5 View Code
Find if entered number is an Armstrong number This program checks if a number is an Armstrong number. Enter a number: 153 153 is an Armstrong number View Code
Print Armstrong number between 1 to 999 This program prints all Armstrong numbers between 1 and 999. - 1, 2, 3, ..., 153, 370, 371, 407 View Code
Print numbers from 1 to 10 in reverse This program prints numbers from 10 to 1 in reverse order. - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 View Code
Biggest of 3 numbers using ternary operator This program finds the biggest of three numbers using a ternary operator. Enter three numbers: 5 10 3 Biggest: 10 View Code
Lowercase to Uppercase This program converts a lowercase character to uppercase. Enter a lowercase character: a Uppercase: A View Code
Uppercase to Lowercase This program converts an uppercase character to lowercase. Enter an uppercase character: A Lowercase: a View Code
Print string inputted in console This program reads a string from the console and prints it. Enter a string: Hello Output: Hello View Code
Read sentence in uppercase and print in lowercase This program reads a sentence in uppercase and prints it in lowercase. Enter a sentence: HELLO WORLD Output: hello world View Code
Read sentence in lowercase and print in uppercase This program reads a sentence in lowercase and prints it in uppercase. Enter a sentence: hello world Output: HELLO WORLD View Code
Swap uppercase to lowercase This program swaps uppercase letters to lowercase and vice versa. Enter a sentence: Hello World Output: hELLO wORLD View Code
Read and print in 2x2 matrix This program reads and prints a 2x2 matrix. Enter elements: 1 2 3 4 Output: 1 2 \n 3 4 View Code
Read and print in 3x3 matrix This program reads and prints a 3x3 matrix. Enter elements: 1 2 3 4 5 6 7 8 9 Output: 1 2 3 \n 4 5 6 \n 7 8 9 View Code
Add Two Numbers Inputted by User Console This program adds two numbers inputted by the user. Enter two numbers: 5 7 Sum: 12 View Code
Read 3 Numbers from Console and Display Biggest This program reads three numbers and displays the biggest. Enter three numbers: 5 10 3 Biggest: 10 View Code
Read 3 Numbers from Console and Display Smallest This program reads three numbers and displays the smallest. Enter three numbers: 5 10 3 Smallest: 3 View Code
Leap Year Using Ternary Operator This program checks if a year is a leap year using a ternary operator. Enter a year: 2020 2020 is a leap year View Code
Accept String and Display Words in Newlines This program accepts a string and displays each word in a new line. Enter a string: Hello World Output: Hello \n World View Code
Print Number of Uppercases and Lowercases in a String This program counts the number of uppercase and lowercase letters in a string. Enter a string: Hello World Uppercase: 2, Lowercase: 8 View Code
Print Prime Numbers Between 1 to 100 This program prints all prime numbers between 1 and 100. - 2, 3, 5, 7, 11, ..., 97 View Code
Prime Numbers Between 1 to 1000 This program prints all prime numbers between 1 and 1000. - 2, 3, 5, 7, 11, ..., 997 View Code
Number to Words (1 to 10) This program converts numbers from 1 to 10 into words. Enter a number: 3 Output: Three View Code
Sum of Two Numbers Using Addition Function This program sums two numbers using a function. Enter two numbers: 5 7 Sum: 12 View Code
Difference of Two Numbers Using Subtract Function This program calculates the difference of two numbers using a function. Enter two numbers: 10 5 Difference: 5 View Code
Accept 10 Numbers and Display Them in Reverse Order This program accepts 10 numbers and displays them in reverse order. Enter 10 numbers: 1 2 3 4 5 6 7 8 9 10 Output: 10 9 8 7 6 5 4 3 2 1 View Code
Print Entered String in Reverse Order This program prints a string in reverse order. Enter a string: Hello Output: olleH View Code
Find String Length Without Using String Function This program finds the length of a string without using string functions. Enter a string: Hello Length: 5 View Code
Compare Two Inputted Strings Using strcmp Function This program compares two strings using the strcmp function. Enter two strings: Hello World Comparison: 0 (equal) View Code
Length of String Using strlen Function This program finds the length of a string using the strlen function. Enter a string: Hello Length: 5 View Code
Find Number of Newlines in Entered String This program counts the number of newlines in a string. Enter a string: Hello\nWorld Newlines: 1 View Code
Find Number of Spaces in Entered String This program counts the number of spaces in a string. Enter a string: Hello World Spaces: 1 View Code
Detect Tabs Entered in a String This program detects tabs in a string. Enter a string: Hello\tWorld Tabs: 1 View Code
Count Lines, Words, and Characters Entered in a String This program counts lines, words, and characters in a string. Enter a string: Hello World Lines: 1, Words: 2, Characters: 11 View Code
LCM of Two Numbers This program calculates the LCM of two numbers. Enter two numbers: 4 6 LCM: 12 View Code
Check if a Number is Prime This program checks if a number is prime. Enter a number: 7 7 is a prime number View Code
Generate List of Prime Numbers This program generates a list of prime numbers up to a given number. Enter a number: 20 Primes: 2, 3, 5, 7, 11, 13, 17, 19 View Code
Calculate Power of a Number This program calculates the power of a number. Enter base and exponent: 2 3 Result: 8 View Code
Check if a Number is Perfect Square This program checks if a number is a perfect square. Enter a number: 16 16 is a perfect square View Code
Sum of First N Prime Numbers This program calculates the sum of the first N prime numbers. Enter N: 5 Sum: 10 View Code
Calculate Area of Triangle This program calculates the area of a triangle. Enter base and height: 5 10 Area: 25 View Code
Calculate Perimeter of Triangle This program calculates the perimeter of a triangle. Enter sides: 3 4 5 Perimeter: 12 View Code
Calculate Area of Parallelogram This program calculates the area of a parallelogram. Enter base and height: 5 10 Area: 50 View Code
Calculate Area of Trapezoid This program calculates the area of a trapezoid. Enter bases and height: 5 7 10 Area: 60 View Code
Convert Binary to Decimal This program converts a binary number to decimal. Enter a binary number: 1010 Decimal: 10 View Code
Convert Decimal to Binary Converts a decimal number to its binary representation. Enter a decimal number: 10 Binary: 1010 View Code
Convert Hexadecimal to Decimal Converts a hexadecimal number to its decimal equivalent. Enter a hexadecimal number: A Decimal: 10 View Code
Convert Decimal to Hexadecimal Converts a decimal number to its hexadecimal representation. Enter a decimal number: 255 Hexadecimal: FF View Code
Find Median Finds the median of a set of numbers. Enter numbers: 1, 3, 2 Median: 2 View Code
Find Mode Finds the mode of a set of numbers. Enter numbers: 1, 2, 2, 3 Mode: 2 View Code
Sort Bubble Sorts an array using the bubble sort algorithm. Enter numbers: 5, 3, 8 Sorted: 3, 5, 8 View Code
Sort Selection Sorts an array using the selection sort algorithm. Enter numbers: 5, 3, 8 Sorted: 3, 5, 8 View Code
Sort Insertion Sorts an array using the insertion sort algorithm. Enter numbers: 5, 3, 8 Sorted: 3, 5, 8 View Code
Find Intersection Finds the intersection of two arrays. Array 1: 1, 2, 3; Array 2: 2, 3, 4 Intersection: 2, 3 View Code
Find Union Finds the union of two arrays. Array 1: 1, 2, 3; Array 2: 2, 3, 4 Union: 1, 2, 3, 4 View Code
Find Difference Finds the difference between two arrays. Array 1: 1, 2, 3; Array 2: 2, 3 Difference: 1 View Code
Merge Sorted Arrays Merges two sorted arrays into one sorted array. Array 1: 1, 3; Array 2: 2, 4 Merged: 1, 2, 3, 4 View Code
Rotate Left Rotates an array to the left by one position. Array: 1, 2, 3 Rotated: 2, 3, 1 View Code
Rotate Right Rotates an array to the right by one position. Array: 1, 2, 3 Rotated: 3, 1, 2 View Code
Longest Common Subsequence Finds the longest common subsequence of two strings. String 1: ABC; String 2: ACB LCS: AC View Code
Check Anagrams Checks if two strings are anagrams. String 1: listen; String 2: silent Anagrams: Yes View Code
Reverse String Reverses a given string. String: hello Reversed: olleh View Code
Check Palindrome Checks if a string is a palindrome. String: racecar Palindrome: Yes View Code
Count Vowels Counts the number of vowels in a string. String: hello Vowels: 2 View Code
Count Consonants Counts the number of consonants in a string. String: hello Consonants: 3 View Code
First Non-Repeating Character Finds the first non-repeating character in a string. String: hello First Non-Repeating: h View Code
Last Non-Repeating Character Finds the last non-repeating character in a string. String: hello Last Non-Repeating: o View Code
Basic Calculator A simple calculator that performs basic operations. Enter expression: 5 + 3 Result: 8 View Code
Evaluate Postfix Evaluates a postfix expression. Expression: 5 3 + Result: 8 View Code
Evaluate Prefix Evaluates a prefix expression. Expression: + 5 3 Result: 8 View Code
Fibonacci (Iteration) Computes Fibonacci numbers using iteration. Enter n: 5 Fibonacci: 5 View Code
Fibonacci (Memoization) Computes Fibonacci numbers using memoization. Enter n: 5 Fibonacci: 5 View Code
Fibonacci (Dynamic) Computes Fibonacci numbers using dynamic programming. Enter n: 5 Fibonacci: 5 View Code
Solve Quadratic Solves a quadratic equation. Enter coefficients: 1, -3, 2 Roots: 2, 1 View Code
Solve Cubic Solves a cubic equation. Enter coefficients: 1, -6, 11, -6 Roots: 3, 2, 1 View Code
Permutations Generates all permutations of a string. String: ABC Permutations: ABC, ACB, BAC, BCA, CAB, CBA View Code
Combinations Generates all combinations of a string. String: ABC Combinations: A, B, C, AB, AC, BC, ABC View Code
Dijkstra's Algorithm Implements Dijkstra's algorithm for shortest paths. Graph: A-B-C Shortest Path: A to C View Code
Bellman-Ford Implements the Bellman-Ford algorithm for shortest paths. Graph: A-B-C Shortest Path: A to C View Code
Check Bipartite Checks if a graph is bipartite. Graph: A-B-C Bipartite: Yes View Code
Prim's Algorithm Implements Prim's algorithm for minimum spanning tree. Graph: A-B-C MST: A-B-C View Code
Kruskal's Algorithm Implements Kruskal's algorithm for minimum spanning tree. Graph: A-B-C MST: A-B-C View Code
DFS Implements Depth First Search. Graph: A-B-C DFS Order: A, B, C View Code
BFS Implements Breadth First Search. Graph: A-B-C BFS Order: A, B, C View Code
N Queens Solves the N Queens problem. N: 4 Solutions: 2 View Code
Sudoku Solves a Sudoku puzzle. Puzzle: 5... Solution: 5... View Code
Longest Increasing Subsequence Finds the longest increasing subsequence. Sequence: 10, 22, 9 LIS: 10, 22 View Code
Longest Decreasing Subsequence Finds the longest decreasing subsequence. Sequence: 10, 22, 9 LDS: 10, 9 View Code
Count Change Counts the number of ways to make change. Amount: 5 Ways: 2 View Code
Maximum Sum Subarray Finds the maximum sum of a contiguous subarray. Array: -2,1,-3,4 Max Sum: 4 View Code
Minimum Sum Subarray Finds the minimum sum of a contiguous subarray. Array: 2,-1,3,-4 Min Sum: -4 View Code

About

A collection of 1000+ C Programs to Learn from for CS and MS Students

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors