C Programs - C Programming Examples (2024)

Last Updated : 15 Feb, 2024

Improve

Improve

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 Programs - C Programming Examples (1)

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

  1. C Hello World Program
  2. C Program to Print Your Own Name
  3. C Program to Print an Integer Entered By the User
  4. C Program to Add Two Numbers
  5. C Program to Check Whether a Number is Prime or Not
  6. C Program to Multiply two Floating-Point Numbers
  7. C Program to Print the ASCII Value of a Character
  8. C Program to Swap Two Numbers
  9. C Program to Calculate Fahrenheit to Celsius
  10. C Program to Find the Size of int, float, double, and char
  11. C Program to Add Two Complex Numbers
  12. CProgram to Print Prime Numbers From 1 to N
  13. C Program to Find Simple Interest
  14. C Program to Find Compound Interest
  15. C Program for Area And Perimeter Of Rectangle

C Program – Control Flow

  1. C Program to Check Whether a Number is Positive, Negative, or Zero
  2. C Program to Check Whether Number is Even or Odd
  3. C Program to Check Whether a Character is Vowel or Consonant
  4. C Program to Find Largest Number Among Three Numbers
  5. C Program to Calculate Sum of Natural Numbers
  6. C Program to Print Alphabets From A to Z Using Loop
  7. C Program to Check Leap Year
  8. C Program to Find Factorial of a Number
  9. C Program to Make a Simple Calculator
  10. C Program to Generate Multiplication Table
  11. C Program to Print Fibonacci Series
  12. CProgram to Find LCM of Two Numbers
  13. C Program to Check Armstrong Number
  14. C Program to Display Armstrong Numbers Between 1 to 1000
  15. C Program to Display Armstrong Number Between Two Intervals
  16. C Program to Reverse a Number
  17. C Program to Check Whether a Number is a Palindrome or Not
  18. C Program to Check Whether a Number is Prime or Not
  19. C Program to Display Prime Numbers Between Intervals
  20. CProgram to Check whether the input number is a Neon Number
  21. C Program to Find All Factors of a Natural Number
  22. Cprogram to Sum of Fibonacci Numbers at Even Indexes up to N Terms

C Program – Pattern Printing

  1. C Program to Print Simple Pyramid Pattern
  2. C Program to Print Given Triangle
  3. C Program to Print 1800 Rotation of Simple Pyramid
  4. C Program to Print Inverted Pyramid
  5. C Program to Print Number Pattern
  6. C Program to Print Character Pattern
  7. C Program to Print Continuous Character Pattern
  8. C Program to Print Hollow Star Pyramid
  9. C Program to Print Inverted Hollow Star pyramid
  10. C Program to Print Hollow Star Pyramid in a Diamond Shape
  11. C Program to Print Full Diamond Shape Pyramid
  12. C Program to Print Pascal’s Pattern Triangle Pyramid
  13. C Program to Print Floyd’s Pattern Triangle Pyramid
  14. C Program to Print Reverse Floyd pattern Triangle Pyramid

C Program – Functions

  1. C Program to Check Prime Number By Creating a Function
  2. C Program to Display Prime Numbers Between Two Intervals Using Functions
  3. C Program to Find All Roots of a Quadratic Equation
  4. C Program to Check Whether a Number can be Express as Sum of Two Prime Numbers
  5. C Program to Find the Sum of Natural Numbers using Recursion
  6. C Program to Calculate the Factorial of a Number Using Recursion
  7. C Program to Find G.C.D Using Recursion
  8. C Program to Reverse a Stack using Recursion
  9. C Program to Calculate Power Using Recursion

C Program – Arrays

  1. C Program to Print a 2D Array
  2. C Program to Find the Largest Element in an Array
  3. C Program to Find the Maximum and Minimum in an Array
  4. C Program to Search an Element in an Array (Binary search)
  5. C Program to Calculate the Average of All the Elements Present in an Array
  6. C Program to Sort an Array using Bubble Sort
  7. C Program to Sort an Array using Merge Sort
  8. C Program to Sort an Array Using Selection Sort
  9. C Program to Sort an Array Using Insertion Sort
  10. C Program to Sort the Elements of an Array in Descending Order
  11. C Program to Sort the Elements of an Array in Ascending Order
  12. C Program to Remove Duplicate Elements From a Sorted Array
  13. C Program to Merge Two Arrays
  14. C Program to Remove All Occurrences of an Element in an Array
  15. C Program to Find Common Array Elements
  16. C Program to Copy All the Elements of One Array to Another Array
  17. C Program For Array Rotation
  18. C Program to Sort the 2D Array Across Rows
  19. C Program to Check Whether Two Matrices Are Equal or Not
  20. C Program to Find the Transpose
  21. C Program to Find the Determinant of a Matrix
  22. C Program to Find the Normal and Trace
  23. C Program to Add Two Matrices
  24. C Program to Multiply Two Matrices
  25. C Program to Print Boundary Elements of a Matrix
  26. C Program to Rotate Matrix Elements
  27. C Program to Compute the Sum of Diagonals of a Matrix
  28. C Program to Interchange Elements of First and Last in a Matrix Across Rows
  29. C Program to Interchange Elements of First and Last in a Matrix Across Columns

C Program – Strings

  1. C Program to Add or Concatenate Two Strings
  2. C Program to Add 2 Binary Strings
  3. C Program to Get a Non-Repeating Character From the Given String
  4. C Program to check if the string is palindrome or not
  5. C Program to Reverse an Array or String
  6. C program to Reverse a String Using Recursion
  7. C Program to Find the Length of a String
  8. C Program to Sort a String
  9. C Program to Check For Pangram String
  10. C Program to Print the First Letter of Each Word
  11. C Program to Determine the Unicode Code Point at a Given Index
  12. C Program to Remove Leading Zeros
  13. C Program to Compare Two Strings
  14. C Program to Compare Two Strings Lexicographically
  15. C Program to Insert a String into Another String
  16. C Program to Split a String into a Number of Sub-Strings

C Program – Conversions

  1. C Program For Boolean to String Conversion
  2. C Program For Float to String Conversion
  3. C Program For Double to String Conversion
  4. C Program For String to Long Conversion
  5. C Program For Long to String Conversion
  6. C Program For Int to Char Conversion
  7. C Program For Char to Int Conversion
  8. C Program For Octal to Decimal Conversion
  9. C Program For Decimal to Octal Conversion
  10. C Program For Hexadecimal to Decimal Conversion
  11. C Program For Decimal to Hexadecimal Conversion
  12. C Program For Decimal to Binary Conversion
  13. C Program For Binary to Decimal Conversion

C Program – Pointers

  1. How to Return a Pointer from a Function in C
  2. How to Declare a Two-Dimensional Array of Pointers in C?
  3. C Program to Find the Largest Element in an Array using Pointers
  4. C Program to Swap Two Numbers
  5. C Program to Sort an Array using Pointers
  6. C Program to Sort a 2D Array of Strings
  7. C Program to Check if a String is a Palindrome using Pointers
  8. C Program to Create a Copy of a Singly Linked List using Recursion

C Program – Structures and Unions

  1. C Program to Store Information of Students Using Structure
  2. C Program to Store Student Records as Structures and Sort them by Name
  3. C Program to Add N Distances Given in inch-feet System using Structures
  4. C Program to Add Two Complex Numbers by Passing Structure to a Function
  5. C Program to Store Student Records as Structures and Sort them by Age or ID
  6. Read/Write Structure to a File in C
  7. Flexible Array Members in a Structure in C

C Program – File IO

  1. C Program to Create a Temporary File
  2. C Program to Read/Write Structure to a File
  3. C Program to Rename a file
  4. C Program to Make a File Read-Only
  5. C program to Compare Two Files and Report Mismatches
  6. C Program to Copy One File into Another File
  7. C Program to Print all the Patterns that Match Given Pattern From a File
  8. C Program to Append the Content of One Text File to Another
  9. C Program to Read Content From One File and Write it Into Another File
  10. C Program to Read and Print all Files From a Zip File

C Program – Date and Time

  1. C Program to Format time in AM-PM format
  2. C program to Print Digital Clock with the Current Time
  3. C Program to Display Dates of Calendar Year in Different Formats
  4. C Program to Display Current Date and Time
  5. C Program to Maximize Time by Replacing ‘_’ in a Given 24-Hour Format Time
  6. C Program to Convert the Local Time to GMT
  7. C Program to Convert Hours into Minutes and Seconds

C Program – More C Programs

  1. C Program to Show Runtime exceptions
  2. C Program to Show Types of errors
  3. C Program to Show Unreachable Code Error
  4. C Program to Find Quotient and Remainder
  5. C Program to Find the Initials of a Name
  6. C Program to Draw a Circle in Graphics
  7. 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.


`; tags.map((tag)=>{ let tag_url = `videos/${getTermType(tag['term_id__term_type'])}/${tag['term_id__slug']}/`; tagContent+=``+ tag['term_id__term_name'] +``; }); tagContent+=`
`; return tagContent; } //function to create related videos cards function articlePagevideoCard(poster_src="", title="", description="", video_link, index, tags=[], duration=0){ let card = `

${secondsToHms(duration)}

${title}
${showLessRelatedVideoDes(htmlToText(description))} ... Read More

${getTagsString(tags)}

`; return card; } //function to set related videos content function getvideosContent(limit=3){ videos_content = ""; var total_videos = Math.min(videos.length, limit); for(let i=0;i

'; } 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 - ") } } ); const video = document.querySelector("video"); const events =[ { 'name':'play', 'callback':()=>{videoPlayCallback(main_video['slug'])} }, ]; events.forEach(event=>{ video.addEventListener(event.name,event.callback); }); }, function (err) { var player = videojs('article-video'); player.createModal('Something went wrong. Please refresh the page to load the video.'); }); /*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(); });*/ });

C Programs - C Programming Examples (2024)

FAQs

What are 10 examples of C? ›

C Programming Examples for Beginners
  • C Hello World Program. #include <stdio.h> Advanced AI & Prompt Engineering Course. ...
  • C Program to Print Your Own Name. #include <stdio.h> ...
  • C Program to Print an Integer Entered By the User. #include <stdio.h> ...
  • C Program to Check Whether a Number is Prime or Not. #include <stdio.h>
Dec 16, 2023

How to memorize C programs? ›

Write out the code yourself, experiment with variations, and try to understand the purpose of each line. This hands-on practice will reinforce your memory. Break it down: Rather than trying to memorize an entire block of code at once, break it down into smaller parts.

What is a real life example of C program? ›

Operating Systems for Computers: The C programming language was used as the operating system's high-level programming language for the first time in UNIX. The C programming language was later utilized to write Microsoft Windows and a number of Android apps.

How to write a C program with an example? ›

Begin your 1st C Program
  1. Open any text editor or IDE and create a new file with any name with a .C extension. e.g. helloworld.c.
  2. Open the file and enter the below code: #include <stdio.h> int main() { printf("Hello, World!" ); return 0; } Run Code >>
  3. Compile and run the code.
May 27, 2024

Where is C used in real life? ›

C is a versatile language that can create all sorts of applications. It's used to write the operating system for many of the world's most popular computers and the software that runs on them. It's also used to create the websites and apps we use daily.

Does anyone still use C programming? ›

Despite the prevalence of higher-level languages, the C programming language continues to empower the world. There are plenty of reasons to believe that C programming will remain active for a long time. Here are some reasons that C is unbeatable, and almost mandatory, for certain applications.

Why is C still useful today? ›

Both C and C++ are widely used in system programming, including operating systems, embedded systems, and hardware-level programming. Knowledge of these languages is essential for working on low-level aspects of software development.

What is C used for today? ›

The first significant use of the C language was to develop the Unix operating system. Today, almost all popular operating systems, such as Microsoft Windows, Linux, and even macOS, are based on Unix. In addition, C has been widely used to develop software such as compilers, text editors, database systems, and more.

What is the first line of the C program? ›

Header File- Line 1 (#include<stdio.h>)

The first and most crucial element that must be included in a C program is the header files content. The term header file refers to a file with the extension <. h> that contains shared C function declarations and macro definitions.

What is C and example? ›

C language is a system programming language because it can be used to do low-level programming (for example driver and kernel). It is generally used to create hardware devices, OS, drivers, kernels, etc. For example, Linux kernel is written in C. It can't be used for internet programming like Java, .Net, PHP, etc.

What is an example of C in math? ›

The capital Latin letter C is used in mathematics as a variable. For example, it appears in geometric formulas as a variable representing the circumference of a circle.

What is an example of this sound C? ›

The Sounds of the Letter c
  • cent: /s/ because it is followed by e.
  • city: /s/ because it is followed by i.
  • cyst: /s/ because it is followed by y.
  • cat: /k/ because it is not followed by e, i or y.
  • cot: /k/ because it is not followed by e, i or y.
  • cut: /k/ because it is not followed by e, i or y.
Aug 6, 2023

How is C used today? ›

Embedded systems: C is often used to program small, low-power devices that are designed to perform specific tasks, such as controlling a motor or monitoring a sensor. Applications: Many applications, such as word processors, web browsers, and media players, are written in C for its performance and flexibility.

References

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6127

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.