Last Updated : 15 Feb, 2024
Comments
Improve
Summarize
Suggest changes
Like Article
Like
Save
Report
C Programs: Practicing and solving problems is the best way to learn anything. Here, we have provided 100+ C programming examples in different categories like basic C Programs, Fibonacci series in C, String, Array, Base Conversion, Pattern Printing, Pointers, etc. These C programs are the most asked interview questions from basic to advanced level.
C Program Topics:
- Basic C Programs
- Control Flow Programs
- Pattern Printing Programs
- Functions Programs
- Arrays Programs
- Strings Programs
- Conversions Programs
- Pointers Programs
- Structures and Unions Programs
- File I/O Programs
- Date and Time Programs
- More C Programs
C Program – Basic
- C Hello World Program
- C Program to Print Your Own Name
- C Program to Print an Integer Entered By the User
- C Program to Add Two Numbers
- C Program to Check Whether a Number is Prime or Not
- C Program to Multiply two Floating-Point Numbers
- C Program to Print the ASCII Value of a Character
- C Program to Swap Two Numbers
- C Program to Calculate Fahrenheit to Celsius
- C Program to Find the Size of int, float, double, and char
- C Program to Add Two Complex Numbers
- CProgram to Print Prime Numbers From 1 to N
- C Program to Find Simple Interest
- C Program to Find Compound Interest
- C Program for Area And Perimeter Of Rectangle
C Program – Control Flow
- C Program to Check Whether a Number is Positive, Negative, or Zero
- C Program to Check Whether Number is Even or Odd
- C Program to Check Whether a Character is Vowel or Consonant
- C Program to Find Largest Number Among Three Numbers
- C Program to Calculate Sum of Natural Numbers
- C Program to Print Alphabets From A to Z Using Loop
- C Program to Check Leap Year
- C Program to Find Factorial of a Number
- C Program to Make a Simple Calculator
- C Program to Generate Multiplication Table
- C Program to Print Fibonacci Series
- CProgram to Find LCM of Two Numbers
- C Program to Check Armstrong Number
- C Program to Display Armstrong Numbers Between 1 to 1000
- C Program to Display Armstrong Number Between Two Intervals
- C Program to Reverse a Number
- C Program to Check Whether a Number is a Palindrome or Not
- C Program to Check Whether a Number is Prime or Not
- C Program to Display Prime Numbers Between Intervals
- CProgram to Check whether the input number is a Neon Number
- C Program to Find All Factors of a Natural Number
- Cprogram to Sum of Fibonacci Numbers at Even Indexes up to N Terms
C Program – Pattern Printing
- C Program to Print Simple Pyramid Pattern
- C Program to Print Given Triangle
- C Program to Print 1800 Rotation of Simple Pyramid
- C Program to Print Inverted Pyramid
- C Program to Print Number Pattern
- C Program to Print Character Pattern
- C Program to Print Continuous Character Pattern
- C Program to Print Hollow Star Pyramid
- C Program to Print Inverted Hollow Star pyramid
- C Program to Print Hollow Star Pyramid in a Diamond Shape
- C Program to Print Full Diamond Shape Pyramid
- C Program to Print Pascal’s Pattern Triangle Pyramid
- C Program to Print Floyd’s Pattern Triangle Pyramid
- C Program to Print Reverse Floyd pattern Triangle Pyramid
C Program – Functions
- C Program to Check Prime Number By Creating a Function
- C Program to Display Prime Numbers Between Two Intervals Using Functions
- C Program to Find All Roots of a Quadratic Equation
- C Program to Check Whether a Number can be Express as Sum of Two Prime Numbers
- C Program to Find the Sum of Natural Numbers using Recursion
- C Program to Calculate the Factorial of a Number Using Recursion
- C Program to Find G.C.D Using Recursion
- C Program to Reverse a Stack using Recursion
- C Program to Calculate Power Using Recursion
C Program – Arrays
- C Program to Print a 2D Array
- C Program to Find the Largest Element in an Array
- C Program to Find the Maximum and Minimum in an Array
- C Program to Search an Element in an Array (Binary search)
- C Program to Calculate the Average of All the Elements Present in an Array
- C Program to Sort an Array using Bubble Sort
- C Program to Sort an Array using Merge Sort
- C Program to Sort an Array Using Selection Sort
- C Program to Sort an Array Using Insertion Sort
- C Program to Sort the Elements of an Array in Descending Order
- C Program to Sort the Elements of an Array in Ascending Order
- C Program to Remove Duplicate Elements From a Sorted Array
- C Program to Merge Two Arrays
- C Program to Remove All Occurrences of an Element in an Array
- C Program to Find Common Array Elements
- C Program to Copy All the Elements of One Array to Another Array
- C Program For Array Rotation
- C Program to Sort the 2D Array Across Rows
- C Program to Check Whether Two Matrices Are Equal or Not
- C Program to Find the Transpose
- C Program to Find the Determinant of a Matrix
- C Program to Find the Normal and Trace
- C Program to Add Two Matrices
- C Program to Multiply Two Matrices
- C Program to Print Boundary Elements of a Matrix
- C Program to Rotate Matrix Elements
- C Program to Compute the Sum of Diagonals of a Matrix
- C Program to Interchange Elements of First and Last in a Matrix Across Rows
- C Program to Interchange Elements of First and Last in a Matrix Across Columns
C Program – Strings
- C Program to Add or Concatenate Two Strings
- C Program to Add 2 Binary Strings
- C Program to Get a Non-Repeating Character From the Given String
- C Program to check if the string is palindrome or not
- C Program to Reverse an Array or String
- C program to Reverse a String Using Recursion
- C Program to Find the Length of a String
- C Program to Sort a String
- C Program to Check For Pangram String
- C Program to Print the First Letter of Each Word
- C Program to Determine the Unicode Code Point at a Given Index
- C Program to Remove Leading Zeros
- C Program to Compare Two Strings
- C Program to Compare Two Strings Lexicographically
- C Program to Insert a String into Another String
- C Program to Split a String into a Number of Sub-Strings
C Program – Conversions
- C Program For Boolean to String Conversion
- C Program For Float to String Conversion
- C Program For Double to String Conversion
- C Program For String to Long Conversion
- C Program For Long to String Conversion
- C Program For Int to Char Conversion
- C Program For Char to Int Conversion
- C Program For Octal to Decimal Conversion
- C Program For Decimal to Octal Conversion
- C Program For Hexadecimal to Decimal Conversion
- C Program For Decimal to Hexadecimal Conversion
- C Program For Decimal to Binary Conversion
- C Program For Binary to Decimal Conversion
C Program – Pointers
- How to Return a Pointer from a Function in C
- How to Declare a Two-Dimensional Array of Pointers in C?
- C Program to Find the Largest Element in an Array using Pointers
- C Program to Swap Two Numbers
- C Program to Sort an Array using Pointers
- C Program to Sort a 2D Array of Strings
- C Program to Check if a String is a Palindrome using Pointers
- C Program to Create a Copy of a Singly Linked List using Recursion
C Program – Structures and Unions
- C Program to Store Information of Students Using Structure
- C Program to Store Student Records as Structures and Sort them by Name
- C Program to Add N Distances Given in inch-feet System using Structures
- C Program to Add Two Complex Numbers by Passing Structure to a Function
- C Program to Store Student Records as Structures and Sort them by Age or ID
- Read/Write Structure to a File in C
- Flexible Array Members in a Structure in C
C Program – File IO
- C Program to Create a Temporary File
- C Program to Read/Write Structure to a File
- C Program to Rename a file
- C Program to Make a File Read-Only
- C program to Compare Two Files and Report Mismatches
- C Program to Copy One File into Another File
- C Program to Print all the Patterns that Match Given Pattern From a File
- C Program to Append the Content of One Text File to Another
- C Program to Read Content From One File and Write it Into Another File
- C Program to Read and Print all Files From a Zip File
C Program – Date and Time
- C Program to Format time in AM-PM format
- C program to Print Digital Clock with the Current Time
- C Program to Display Dates of Calendar Year in Different Formats
- C Program to Display Current Date and Time
- C Program to Maximize Time by Replacing ‘_’ in a Given 24-Hour Format Time
- C Program to Convert the Local Time to GMT
- C Program to Convert Hours into Minutes and Seconds
C Program – More C Programs
- C Program to Show Runtime exceptions
- C Program to Show Types of errors
- C Program to Show Unreachable Code Error
- C Program to Find Quotient and Remainder
- C Program to Find the Initials of a Name
- C Program to Draw a Circle in Graphics
- Printing Source Code of a C Program Itself
FAQs on C Program
Q1: What is C programming?
Answer:
C is a structured, high-level, and general-purpose programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs. C language is considered as the mother language of all modern programming languages, widely used for developing system software, embedded software, and application software.
Q2: How do I write a “Hello, World!” program in C?
Answer:
To write a “Hello, World!” program in C, you can use the following code:
#include <stdio.h>
int main() {
printf(“Hello, World!\n”);
return 0;
}
This code uses the printf function to display the “Hello, World!” message on the screen.
Q3: Why should you learn C Programming?
Answer:
There are many reasons why you should learn C programming:
- Versatility
- Efficiency
- Portability
- Widely used
- Foundation for other languages
- Employment opportunities and more.
${secondsToHms(duration)}
${getTagsString(tags)}
'; } else{ let view_all_url = `${GFG_SITE_URL}videos/`; videos_content+=`
View All
`; } // videos_content+= '
'; } } return videos_content; } //function to show main video content with related videos content async function showMainVideoContent(main_video, course_link){ //Load main video $(".video-main").html(`
`); require(["ima"], function() { var player = videojs('article-video', { controls: true, // autoplay: true, // muted: true, controlBar: { pictureInPictureToggle: false }, playbackRates: [0.5, 0.75, 1, 1.25, 1.5, 2], poster: main_video['meta']['largeThumbnail'], sources: [{src: main_video['source'], type: 'application/x-mpegURL'}], tracks: [{src: main_video['subtitle'], kind:'captions', srclang: 'en', label: 'English', default: true}] },function() { player.qualityLevels(); try { player.hlsQualitySelector(); } catch (error) { console.log("HLS not working - ") } document.getElementById('article-video-tab-content').style.display = 'block'; } ); const video = document.querySelector("video"); const events =[ { 'name':'play', 'callback':()=>{videoPlayCallback(main_video['slug'])} }, ]; events.forEach(event=>{ video.addEventListener(event.name,event.callback); }); // error handling for no compatible source player.on('error', function() { var error = player.error(); console.log("Video Error: ", error); if (error && error.code === 4) { console.log("No compatible source was found for this media."); hideVideoPlayer(); } }); }, function(err) { var player = videojs('article-video'); player.createModal('Something went wrong. Please refresh the page to load the video.'); hideVideoPlayer(); // hiding video in case of timeout (requirejs) console.log(err); }); // function to hide the video player function hideVideoPlayer() { var videoPlayer = document.getElementById('article-video'); if (videoPlayer) { videoPlayer.parentNode.removeChild(videoPlayer); } } /*let video_date = main_video['time']; video_date = video_date.split("/"); video_date = formatDate(video_date[2], video_date[1], video_date[0]); let share_section_content = `
${video_date}
`;*/ let hasLikeBtn = false; // console.log(share_section_content); var data = {}; if(false){ try { if((loginData && loginData.isLoggedIn == true)){ const resp = await fetch(`${API_SCRIPT_URL}logged-in-video-details/${main_video['slug']}/`,{ credentials: 'include' }) if(resp.status == 200 || resp.status == 201){ data = await resp.json(); share_section_content+= `
`; hasLikeBtn = true; } else { share_section_content+= `
`; } } else { share_section_content+= `
`; } //Load share section // $(".video-share-section").html(share_section_content); // let exitCond = 0; // const delay = (delayInms) => { // return new Promise(resolve => setTimeout(resolve, delayInms)); // } // while(!loginData){ // let delayres = await delay(1000); // exitCond+=1; // console.log(exitCond); // if(exitCond>5){ // break; // } // } // console.log(loginData); /*if(hasLikeBtn && loginData && loginData.isLoggedIn == true){ setLiked(data.liked) setSaved(data.watchlist) }*/ } catch (error) { console.log(error); } } //Load video content like title, description if(false){ $(".video-content-section").html(`
${main_video['title']}
${hideMainVideoDescription(main_video['description'], main_video['id'])}
${getTagsString(main_video['category'])} ${(course_link.length)? `
View Course
`:''} `); let related_vidoes = main_video['recommendations']; if(!!videos && videos.length>0){ //Load related videos $(".related-videos-content").html(getvideosContent()); } } //show video content // element = document.getElementById('article-video-tab-content'); // element.style.display = 'block'; $('.spinner-loading-overlay:eq(0)').remove(); $('.spinner-loading-overlay:eq(0)').remove(); } await showMainVideoContent(video_data, course_link); // fitRelatedVideosDescription(); } catch (error) { console.log(error); } } getVideoData(); /* $(window).resize(function(){ onWidthChangeEventsListener(); }); $('#video_nav_tab').click('on', function(){ fitRelatedVideosDescription(); });*/ });