Tutorials Class - Logo

  • C All Exercises & Assignments

Write a C program to check whether a number is even or odd

Description:

Write a C program to check whether a number is even or odd.

Note: Even number is divided by 2 and give the remainder 0 but odd number is not divisible by 2 for eg. 4 is divisible by 2 and 9 is not divisible by 2.

Conditions:

  • Create a variable with name of number.
  • Take value from user for number variable.

Enter the Number=9 Number is Odd.

Write a C program to swap value of two variables using the third variable.

You need to create a C program to swap values of two variables using the third variable.

You can use a temp variable as a blank variable to swap the value of x and y.

  • Take three variables for eg. x, y and temp.
  • Swap the value of x and y variable.

Write a C program to check whether a user is eligible to vote or not.

You need to create a C program to check whether a user is eligible to vote or not.

  • Minimum age required for voting is 18.
  • You can use decision making statement.

Enter your age=28 User is eligible to vote

Write a C program to check whether an alphabet is Vowel or Consonant

You need to create a C program to check whether an alphabet is Vowel or Consonant.

  • Create a character type variable with name of alphabet and take the value from the user.
  • You can use conditional statements.

Enter an alphabet: O O is a vowel.

Write a C program to find the maximum number between three numbers

You need to write a C program to find the maximum number between three numbers.

  • Create three variables in c with name of number1, number2 and number3
  • Find out the maximum number using the nested if-else statement

Enter three numbers: 10 20 30 Number3 is max with value of 30

Write a C program to check whether number is positive, negative or zero

You need to write a C program to check whether number is positive, negative or zero

  • Create variable with name of number and the value will taken by user or console
  • Create this c program code using else if ladder statement

Enter a number : 10 10 is positive

Write a C program to calculate Electricity bill.

You need to write a C program to calculate electricity bill using if-else statements.

  • For first 50 units – Rs. 3.50/unit
  • For next 100 units – Rs. 4.00/unit
  • For next 100 units – Rs. 5.20/unit
  • For units above 250 – Rs. 6.50/unit
  • You can use conditional statements.

Enter the units consumed=278.90 Electricity Bill=1282.84 Rupees

Write a C program to print 1 to 10 numbers using the while loop

You need to create a C program to print 1 to 10 numbers using the while loop

  • Create a variable for the loop iteration
  • Use increment operator in while loop

1 2 3 4 5 6 7 8 9 10

  • C Exercises Categories
  • C Top Exercises
  • C Decision Making

Browse Course Material

Course info, instructors.

  • Daniel Weller
  • Sharat Chikkerur

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages
  • Software Design and Engineering

Learning Resource Types

Practical programming in c, assignments.

ASSN # TOPICS ASSIGNMENTS SOLUTIONS
1 Writing, compiling, and debugging programs; preprocessor macros; C file structure; variables; functions and problem statements; returning from functions ( ) ( )
2 Types, operators, expressions ( ) ( )
3 Control flow, functions, variable scope, static and global variables, I/O: printf and scanf, file I/O, character arrays, error handling, labels and goto

( )

( ) (This ZIP file contains: 1 .txt file and 2 .c files.)

( )
4 Pointers, arrays, strings, searching and sorting algorithms ( ) ( )
5 Linked lists, trees ( ) ( )
6a Pointers to pointers, multidimensional arrays, stacks and queues

( )

( ) (This ZIP file contains: 1 .txt file and 2 .c files.)

( )
6b Function pointers, hash table

( )

( ) (This ZIP file contains: 1 .txt file and 2 .c files.)

( )
7 Using and creating libraries, B-trees and priority queues

( )

( ) (This ZIP file contains: 2 .c files and 1 .db file.)

( ) (This ZIP file contains: 5 .txt files and 5 .c files.)

facebook

You are leaving MIT OpenCourseWare

C Functions

C structures, c reference, c exercises.

You can test your C skills with W3Schools' Exercises.

We have gathered a variety of C exercises (with answers) for each C Chapter.

Try to solve an exercise by editing some code, or show the answer to see what you've done wrong.

Count Your Score

You will get 1 point for each correct answer. Your score and total score will always be displayed.

Start C Exercises

Start C Exercises ❯

If you don't know C, we suggest that you read our C Tutorial from scratch.

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

Code With C

The Way to Programming

  • C Tutorials
  • Java Tutorials
  • Python Tutorials
  • PHP Tutorials
  • Java Projects

200+ Interview Questions for C Programming – 2024

CodeWithC

You might think of C interview questions to be way more difficult compared to your general exam question papers. Yes, C interview questions are not easy to answer, but they are not that difficult too. Your confidence to answer such interview questions correctly depends on your knowledge level related to the question, and your ability to cope up with and analyze a new problem.

In this article, we will go through some commonly asked as well as interesting questions along with their answers to help students prepare for C interviews.

Attempts have been made to cover all parts of the language in the C interview questions presented in this post. I have included relevant, interesting and common questions/problems from C basics, operators, functions, arrays, pointers, data structures, and more. To provide students a clear concept of the problems, I have included source codes, additional explanations as well as images in some questions.

The most commonly asked or frequently asked C interview questions are like What is…..What is the difference between….Write a C program to…..Find the error in the source code given below….What is the output of the source code given below….etc. I have tried to include different types of questions from different chapters/topics of the C programming language.

The C interview questions here have been divided into 3 parts – frequently asked, interesting questions and other most common C questions. I have provided complete answers along with source codes in the first two parts; I have left the third part with questions only for your own practice.

200+ Frequently Asked C Interview Questions & Answers:

C Interview Questions

Q1. Mention the different storage classes in C.

This might be one of the most debated C interview questions; the answer to this question varies book by book, and site by site on the internet. Here, I would like to make it clear there are only two storage classes in C, and the rest are storage class specifiers.

As per reference manual of “The C Programming Language” by: Brian W. Kernighan and Dennis M. Ritchie, in the Appendix A of the reference manual, the very first line says: There are two storage classes: automatic and static . [ The C programing Language 2nd Edition,Brian W. Kernighan ,Dennis M. Ritchie ]

Q2. What are the different storage class specifiers in C?

There are 4 storage class specifiers in C, out of which auto and static act as storage classes as well. So, the storage class specifiers are:

Q3. What are library functions in C?

Library functions are the predefined functions in C, stored in .lib files.

Q4. Where are the auto variables stored?

Auto variables are stored in the main memory. The default value of auto variables is garbage value.

Q5. What is the difference between i++ and ++i?

One of the most commonly asked C interview questions or viva questions – i++ and ++i. The expression i++ returns the old value and then increases i by 1, whereas the expression ++i first increases the value of i by 1 and then returns the new value.

Q6. What is l-value in C? Mention its types.

Location value, commonly known as the l-value, refers to an expression used on the left side of an assignment operator. For example: in the expression “x = 5”, x is the l-value and 5 is the r-value.

There are two types of l-value in C – modifiable l-value and non-modifiable l-value. modifiable l-value denoted a l-value which can be modified. non-modifiable l-value denote a l-value which cannot be modified. const variables are non-modifiable l-value.

Q7. Can i++ and ++i be used as l-value in C?

In C both i++ and ++i cannot be used as l-value. Whereas in C++, ++i can be used as l-value, but i++ cannot be.

Q8. Which of the following shows the correct hierarchy of arithmetic operations in C?

(1) / + * – (2) * – / + (3) + – / * (4) * / + –

4 is the correct answer.

Q9. Which bit wise operator is suitable for

  • checking whether a particular bit is on or off? Ans. The bitwise AND operator.
  • turning off a particular bit in a number? Ans. The bitwise AND operator.
  • putting on a particular bit in a number? Ans. The bitwise OR operator.

Q10. Can a C program be written without using the main function?

This is one of the most interesting C interview questions. I guess, up until now, you might not have ever written a C program without using the main function. But, a program can be executed without the main function. See the example below:

Now, lets see what’s happening within the source code. Here, #define acts as the main function to some extent. We are basically using #define as a preprocessor directive  to give an impression that the source code executes without the main function.

Q11. What is the output of printf(“%d”); ?

For printf(“%d”, a); the compiler will print the corresponding value of a. But in this case, there is nothing after %d, so the compiler will show garbage value in output screen.

Q12. What is the difference between printf() and sprintf() ?

printf() statement writes data to the standard output device, whereas sprintf() writes data to the character array.

Q13. What is the difference between %d and %*d ?

Here, %d gives the original value of the variable, whereas %*d gives the address of the variable due to the use of pointer.

Q14. Which function – gets() or fgets(), is safe to use, and why?

Neither gets() nor fgets() is completely safe to use. When compared, fgets() is safe to use than gets() because with fgest() a maximum input length can be specified.

Q15. Write a C program to print “Programming is Fun” without using semicolon (;) .

Here’s a typical source code to print “Programming is Fun”.

There’s not much trick in printing the line without using the semicolon. Simply use the printf statement inside the if condition as shown below.

An extension of the above can be – write a C program to print “;” without using a semicolon.

Q16. What is the difference between pass by value and pass by reference?

This is another very important topic in this series of C interview questions. I will try to explain this in detail with source code and output.

Pass by Value:

This is the process of calling a function in which actual value of arguments are passed to call a function. Here, the values of actual arguments are copied to formal arguments, and as a result, the values of arguments in the calling function are unchanged even though they are changed in the called function. So, passing by value to function is restricted to one way transfer of information. The following example illustrates the mechanism of passing by value to function.

In this example, the values of x and y have been passed into the function and they have been swapped in the called function without any change in the calling function.

Pass by Reference:

In pass by reference, a function is called by passing the address of arguments instead of passing the actual value. In order to pass the address of an argument, it must be defined as a pointer. The following example illustrates the use of pass by reference.

In this example, addresses of x and y have been passed into the function, and their values are swapped in the called function. As a result of this, the values are swapped in calling function also.

Q17. Write a C program to swap two variables without using a third variable.

This is one of the very common C interview questions. It can be solved in a total of five steps. For this, I have considered two variables as a and b, such that a = 5 and b = 10.

Q18. When is a switch statement better than multiple if statements?

When two or more than two conditional expressions are based on a single variable of numeric type, a switch statement is generally preferred over multiple if statements.

Q19. Write a C program to print numbers from 1 to n without using loop.

Q20. What is the difference between declaration and definition of a function?

Declaration of a function in the source code simply indicates that the function is present somewhere in the program, but memory is not allocated for it. Declaration of a function helps the program understand the following:

  • what are the arguments to that function
  • their data types
  • the order of arguments in that function
  • the return type of the function

Definition of a function, on the other hand, acts like a super set of declaration. It not only takes up the role of declaration, but also allocates memory for that function.

Q21. What are static functions? What is their use in C?

In the C programming language, all functions are global by default. Therefore, to make a function static, the “static” keyword is used before the function. Unlike the global functions, access to static functions in C is restricted to the file where they are declared.

The use of static functions in C are:

  • to make a function static
  • to restrict access to functions
  • to reuse the same function name in other file

Q22. Mention the advantages and disadvantages of arrays in C.

Advantages:

  • Each element of array can be easily accessed.
  • Array elements are stored in continuous memory location.
  • With the use of arrays, too many variables need not be declared.
  • Arrays have a wide application in data structure.

Disadvantages:

  • Arrays store only similar type of data.
  • Arrays occupy and waste memory space.
  • The size of arrays cannot be changed at the run time.

Q23. What are array pointers in C?

Array whose content is the address of another variable is known as array pointer. Here’s an example illustrating array pointers in C.

Q24. How will you differentiate  char const* p and const char* p ?

In char const* p, the pointer ‘p’ is constant, but not the character referenced by it. Here, you cannot make ‘p’ refer to any other location, but you can change the value of the char pointed by ‘p’.

In const char* p, the character pointed by ‘p’ is constant. Here, unlike the upper case, you cannot change the value of character pointed by ‘p’, but you can make ‘p’ refer to any other location.

Q25. What is the size of void pointer in C?

Whether it’s char pointer, function pointer, null pointer, double pointer, void pointer or any other, the size of any type of pointer in C is of two byte. In C, the size of any pointer type is independent of data type.

Q26. What is the difference between dangling pointer and wild pointer?

Both these pointers don’t point to a particular valid location.

A pointer is called dangling if it was pointing to a valid location earlier, but now the location is invalid. This happens when a pointer is pointing at the memory address of a variable, but afterwards some variable has been deleted from that particular memory location, while the pointer is still pointing at that memory location. Such problems are commonly called dangling pointer problem and the output is garbage value.

Wild pointer too doesn’t point to any particular memory location. A pointer is called wild if it is not initialized at all. The output in this case is any address.

Q27. What is the difference between wild pointer and null pointer?

Wild pointer is such a pointer which doesn’t point to any specific memory location as it is not initialized at all. Whereas, null pointer is the one that points the base address of segment. Literally, null pointers point at nothing.

Q28. What is far pointer in C?

C Interview Questions - Far Pointer

Q29. What is FILE?

FILE is simply a predefined data type defined in stdio.h file.

Q30. What are the differences between Structure and Unions?

  • Every member in structure has its own memory, whereas the members in a union share the same member space.
  • Initialization of all the member at the same time is possible in structures but not in unions.
  • For the same type of member, a structure requires more space than a union.
  • Different interpretations of the same memory space is possible in union but not in structures.

Q31. Write a C program to find the size of structure without using sizeof operator?

Q32. What is the difference between .com program and .exe program?

Both these programs are executable programs, and all drivers are .com programs.

  • .com program executes faster than .exe program.
  • .com file has higher preference than .exe type.

Some Interesting C Interview Questions:

Interesting C Interview Questions

The execution depends on the amount machine instruction to carry out the operation in the expression. n++ requires only a single machine instruction, such as INR, to carry out the increment operation. On the other hand, n+1 requires more machine instructions to carry out this operation. Hence, n++ executes faster than n+1 in C.

2. Is int x; a declaration or a definition? What about int x = 3; and x = 3; ?

3. What is the parent of the main() function?

The parent of main() function is header files – the <stdio.h> header file.

4. Write a C program to print the next prime number for any number entered by the user.

5. Write a C program to solve the “Tower of Hanoi” question without using recursion.

Try this yourself.

6. Create an array of char type whose size is not known until its run, i.e., the size must be given by the user.

Hints are given in the source code below. If you want to use array finish, you must free it to return resources to memory.

Other Commonly Asked C Interview Questions:

These are some other commonly asked C interview questions or exam/viva questions. Try answering these on your own, and if you need help with any, mention them in the comments section at the end.

Expression – An expression is the combination of operands and operators.

  • What is the difference between declaration and definition of a variable?
  • Can static variables be declared in a header file?
  • Can a variable be both constant and volatile?
  • What are C identifiers?
  • Can include files in C be nested?
  • What are flag values?
  • Write the prototype of printf function.
  • What is the use of void data type in C?
  • What is the use of typedef in C?
  • Differentiate for loop and while loop.
  • Why is the main() function used in C?
  • What are macros? Mention their advantages and disadvantages.
  • Mention the advantages of a macro over a function.
  • What is function recursion in C?
  • What keyword is used to rename a function in C?
  • What is the difference between Calloc() and Malloc() ?
  • What is the difference between strings and character arrays?
  • What are the differences between sizeof operator and strlen function?
  • Differentiate between static memory allocation and dynamic memory allocation.
  • What are the uses of pointers in C?
  • What is a null pointer assignment error?
  • What are enumerations?
  • Mention the advantages of using unions in C.
  • Differentiate a linker and linkage.
  • What is the difference between C++ and C programming?
  • What are the advantages of C programming?
  • What are the disadvantages of C programming?
  • Give an example of error handling in C programming.
  • How do you write a program in C?
  • What is the difference between C and C++ programming?
  • What is the use of C++?
  • Give an example of polymorphism in C++.
  • What is the difference between object-oriented and procedural programming?
  • What are the different memory models?
  • What is the difference between static and dynamic linking?
  • Explain the use of pointer.
  • What is the difference between a variable and a constant?
  • Explain the scope of variables.
  • What is a statement?
  • Explain the difference between goto and break statements?
  • What is the difference between the forward and backward jump statements?
  • How do you declare an integer variable?
  • Define what a loop is?
  • What is the difference between while and for loops?
  • What is the difference between a conditional and a loop?
  • Define what an array is?
  • Explain the use of malloc and free functions.
  • What are the types of data structures?
  • What are the different data types in C?
  • What is the difference between a data structure and a variable?
  • What is the difference between a character and a string?
  • Define the difference between a pointer and an array.
  • Define the difference between a linked list and a queue.
  • Define the difference between a stack and a heap.
  • Define the difference between a stack and a queue.
  • What is the difference between char and character?
  • What is the difference between signed and unsigned integer types?
  • What is the difference between byte and word types?
  • What is the difference between pointer and array types?
  • What is the difference between float, double, and long integer types?
  • How to declare and use variables?
  • What is the difference between integer and real types?
  • What is the difference between structure and union types?
  • What is the difference between arrays and pointers?
  • What is the difference between functions and subroutines?
  • What are the return values of functions?
  • What is the difference between switch and if statement?
  • What are the differences between for loop and while loop?
  • What is the difference between goto and break statements?
  • What is the difference between enum and typedef?
  • What are the differences between const and volatile?
  • What is the difference between inline and static?
  • What is the difference between static and volatile?
  • What is the difference between static and extern?
  • What is the difference between extern and static?
  • What is the difference between static and global?
  • What are the differences between typedef, enum, union, and struct?
  • What is the difference between char, int, float, and long?
  • What is the difference between void and int?
  • What is the difference between void and char?
  • What are the differences between union and struct types?
  • What are the differences between function and procedure types?
  • What is the difference between void and return types?
  • What is the difference between class and interface types?
  • What is the difference between pointers and arrays?
  • What is the difference between arrays and references?
  •  What is the difference between arrays and pointers?

So, what do you think of the C interview questions mentioned here? Did you find them new, difficult, interesting or boring: we would like to hear your feedback. Also, you can suggest us more interview questions that would suit this post.

You Might Also Like

Program c: building foundations with the c language, s in c programming: understanding string manipulation, program with c: starting your journey in c programming, c programming language: the foundation of system software, programs c language: creating efficient solutions.

C++ project

Nice article, I was searching for something like this i was browsing the net since ours but dint find exact question and answers which justifies the question your article is the best and have all the important questions include in it.

program to swap two variables without using a third variable doesn’t work in code blocks?

int main() { int a, b; scanf(“%d%d”,&a,&b); a=a+b; b=a-b; a=a-b; printf(“\n After swap a=%d b=%d”,a,b); return 0; }

Q: How we use graphics in C ?

Too nyc will help to upcoming students who are searching jobs

Which c programs are may ask in national c code writing competitions

Q:- Which program is used to convert object code into source code in c/c++? plz help me

I sort of get this question as — how does a source code become a program? Are you asking how does a source code get converted into object code?

If yes, the answer is compiler. Source code is turned into object code by a compiler. Then, once the object code is passed through a linker, an executable program comes into existence.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Posts

62 Creating a Google Sheet to Track Google Drive Files: Step-by-Step Guide

Creating a Google Sheet to Track Google Drive Files: Step-by-Step Guide

codewithc 61 Cutting-Edge Artificial Intelligence Project Unveiled in Machine Learning World

Cutting-Edge Artificial Intelligence Project Unveiled in Machine Learning World

75 Enhancing Exams with Image Processing: E-Assessment Project

Enhancing Exams with Image Processing: E-Assessment Project

73 Cutting-Edge Blockchain Projects for Cryptocurrency Enthusiasts - Project

Cutting-Edge Blockchain Projects for Cryptocurrency Enthusiasts – Project

67 Artificial Intelligence Marvel: Cutting-Edge Machine Learning Project

Artificial Intelligence Marvel: Cutting-Edge Machine Learning Project

Privacy overview.

en_US

Sign in to your account

Username or Email Address

Remember Me

  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors
  • C File Handling
  • C Cheatsheet
  • C Interview Questions

To learn anything effectively, practicing and solving problems is essential. To help you master C programming, we have compiled over 100 C programming examples across various categories, including basic C programs, Fibonacci series, strings, arrays, base conversions, pattern printing, pointers, and more. These C Examples cover a range of questions, from fundamental concepts to advanced topics, and are frequently asked in C-based programming interviews .

C Programs

C Program Topics :

  • Basic C Program
  • Control Flow
  • Pattern Printing
  • Conversions
  • Structures and Unions
  • Date and Time
  • More C Programs

Prerequisite : Before you start with these C programs, take a look at our C tutorial to get a good understanding of the basics.

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  
  • C Program 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
  • C Program 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 Display Prime Numbers Between Intervals
  • C Program to Check whether the input number is a Neon Number
  • C Program to Find All Factors of a Natural Number
  • C program 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 180 0 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 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

What is c programming.

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.

How do I write a “Hello, World!” program in C?

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.

Why should you learn C Programming?

There are many reasons why you should learn C programming: Versatility Efficiency Portability Widely used Foundation for other languages Employment opportunities and more.

Please Login to comment...

Similar reads.

  • Best 10 IPTV Service Providers in Germany
  • Python 3.13 Releases | Enhanced REPL for Developers
  • IPTV Anbieter in Deutschland - Top IPTV Anbieter Abonnements
  • Best SSL Certificate Providers in 2024 (Free & Paid)
  • Content Improvement League 2024: From Good To A Great Article

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Master Programming

C Programming Exercises With Solutions (PDF)

Here you will get C Programming Exercises With Solutions.

Here I am going to provide you a document of these, which you can download and make changes according to your own.

C Programming Exercises With Solutions

Download C Programming Practical Assignments Questions

Download Now

Download C Programming Exercises With Solutions PDF (2020)

Download c programming exercises with solutions pdf (2021), download 100+ c programming exercises pdf.

If you face any problem in downloading C Programming Practical Assignments Questions and Solutions PDFs, then tell us in the comment below and you will definitely share this post with your friends so that they can also be of some help.

Also Read -:

  • Database Management System Lab Assignment Exercise Question and There Solutions
  • C++ Lab Exercises And Solutions (PDF) – Master Programming
  • Web Technology Lab Assignment Question And Solutions
  • Pc Software Practical Assignment Question And Solutions
  • Operating System with Linux Lab Assignment Question And Solutions (PDF)

' src=

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding and Competitive Programming

Codeforwin

If else programming exercises and solutions in C

if...else is a branching statement . It is used to take an action based on some condition. For example – if user inputs valid account number and pin, then allow money withdrawal.

If statement works like “If condition is met, then execute the task” . It is used to compare things and take some action based on the comparison. Relational and logical operators supports this comparison.

C language supports three variants of if statement.

  • Simple if statement
  • if…else and if…else…if statement
  • Nested if…else statement

As a programmer you must have a good control on program execution flow. In this exercise we will focus to control program flow using if...else statements.

Always feel free to drop your queries and suggestions below in the comments section . I will try to get back to you asap.

Required knowledge

Basic C programming , Relational operators , Logical operators

List of if...else programming exercises

  • Write a C program to find maximum between two numbers.
  • Write a C program to find maximum between three numbers.
  • Write a C program to check whether a number is negative, positive or zero.
  • Write a C program to check whether a number is divisible by 5 and 11 or not.
  • Write a C program to check whether a number is even or odd.
  • Write a C program to check whether a year is leap year or not.
  • Write a C program to check whether a character is alphabet or not.
  • Write a C program to input any alphabet and check whether it is vowel or consonant.
  • Write a C program to input any character and check whether it is alphabet, digit or special character.
  • Write a C program to check whether a character is uppercase or lowercase alphabet .
  • Write a C program to input week number and print week day .
  • Write a C program to input month number and print number of days in that month.
  • Write a C program to count total number of notes in given amount .
  • Write a C program to input angles of a triangle and check whether triangle is valid or not.
  • Write a C program to input all sides of a triangle and check whether triangle is valid or not.
  • Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.
  • Write a C program to find all roots of a quadratic equation .
  • Write a C program to calculate profit or loss.
  • Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F
  • Write a C program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95%
  • Write a C program to input electricity unit charges and calculate total electricity bill according to the given condition: For first 50 units Rs. 0.50/unit For next 100 units Rs. 0.75/unit For next 100 units Rs. 1.20/unit For unit above 250 Rs. 1.50/unit An additional surcharge of 20% is added to the bill

"Hello World!" in C Easy C (Basic) Max Score: 5 Success Rate: 85.64%

Playing with characters easy c (basic) max score: 5 success rate: 84.40%, sum and difference of two numbers easy c (basic) max score: 5 success rate: 94.61%, functions in c easy c (basic) max score: 10 success rate: 96.02%, pointers in c easy c (basic) max score: 10 success rate: 96.62%, conditional statements in c easy c (basic) max score: 10 success rate: 96.93%, for loop in c easy c (basic) max score: 10 success rate: 93.80%, sum of digits of a five digit number easy c (basic) max score: 15 success rate: 98.66%, bitwise operators easy c (basic) max score: 15 success rate: 94.99%, printing pattern using loops medium c (basic) max score: 30 success rate: 95.95%, cookie support is required to access hackerrank.

Seems like cookies are disabled on this browser, please enable them to open this website

Sharp Tutorial

Java Script

  • Python Programs
  • Java Script Program
  • Java Program
  • Ask Your Question
  • Java Script FAQ
  • CBSE Comp Science Question Paper
  • MDU python question Papers
  • Java Assignment
  • C Assignment
  • Python assignment
  • Java Script Assignment
  • Python Interview Question
  • Video Tutorials
  • 11th,12th Class Python Syllabus CBSE Board
  • ICSE Board 11-12 Computer Syllabus
  • Top 10 Programming Language 2020

Learn C practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn c interactively.

The best way to learn C programming is by practicing examples. The page contains examples on basic concepts of C programming. You are advised to take the references from these examples and try them on your own.

All the programs on this page are tested and should work on all platforms.

Want to learn C Programming by writing code yourself? Enroll in our Interactive C Course for FREE.

  • C Program to Create Pyramids and Patterns
  • C Program to Check Prime Number
  • C Program to Check Palindrome Number
  • C Program to Print Hello World
  • C "Hello, World!" Program
  • C Program to Print an Integer (Entered by the User)
  • C Program to Add Two Integers
  • C Program to Multiply Two Floating-Point Numbers
  • C Program to Find ASCII Value of a Character
  • C Program to Compute Quotient and Remainder
  • C Program to Find the Size of int, float, double and char
  • C Program to Demonstrate the Working of Keyword long
  • C Program to Swap Two Numbers
  • C Program to Check Whether a Number is Even or Odd
  • C Program to Check Whether a Character is a Vowel or Consonant
  • C Program to Find the Largest Number Among Three Numbers
  • C Program to Find the Roots of a Quadratic Equation
  • C Program to Check Leap Year
  • C Program to Check Whether a Number is Positive or Negative
  • C Program to Check Whether a Character is an Alphabet or not
  • C Program to Calculate the Sum of Natural Numbers
  • C Program to Find Factorial of a Number
  • C Program to Generate Multiplication Table
  • C Program to Display Fibonacci Sequence
  • C Program to Find GCD of two Numbers
  • C Program to Find LCM of two Numbers
  • C Program to Display Characters from A to Z Using Loop
  • C Program to Count Number of Digits in an Integer
  • C Program to Reverse a Number
  • C Program to Calculate the Power of a Number
  • C Program to Check Whether a Number is Palindrome or Not
  • C Program to Check Whether a Number is Prime or Not
  • C Program to Display Prime Numbers Between Two Intervals
  • C Program to Check Armstrong Number
  • C Program to Display Armstrong Number Between Two Intervals
  • C Program to Display Factors of a Number
  • C Program to Make a Simple Calculator Using switch...case
  • C Program to Display Prime Numbers Between Intervals Using Function
  • C Program to Check Prime or Armstrong Number Using User-defined Function
  • C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
  • C Program to Find the Sum of Natural Numbers using Recursion
  • C Program to Find Factorial of a Number Using Recursion
  • C Program to Find G.C.D Using Recursion
  • C Program to Convert Binary Number to Decimal and vice-versa
  • C Program to Convert Octal Number to Decimal and vice-versa
  • C Program to Convert Binary Number to Octal and vice-versa
  • C Program to Reverse a Sentence Using Recursion
  • C program to calculate the power using recursion
  • C Program to Calculate Average Using Arrays
  • C Program to Find Largest Element in an Array
  • C Program to Calculate Standard Deviation
  • C Program to Add Two Matrices Using Multi-dimensional Arrays
  • C Program to Multiply Two Matrices Using Multi-dimensional Arrays
  • C Program to Find Transpose of a Matrix
  • C Program to Multiply two Matrices by Passing Matrix to a Function
  • C Program to Access Array Elements Using Pointer
  • C Program Swap Numbers in Cyclic Order Using Call by Reference
  • C Program to Find Largest Number Using Dynamic Memory Allocation
  • C Program to Find the Frequency of Characters in a String
  • C Program to Count the Number of Vowels, Consonants and so on
  • C Program to Remove all Characters in a String Except Alphabets
  • C Program to Find the Length of a String
  • C Program to Concatenate Two Strings
  • C Program to Copy String Without Using strcpy()
  • C Program to Sort Elements in Lexicographical Order (Dictionary Order)
  • C Program to Store Information of a Student Using Structure
  • C Program to Add Two Distances (in inch-feet system) using Structures
  • C Program to Add Two Complex Numbers by Passing Structure to a Function
  • C Program to Calculate Difference Between Two Time Periods
  • C Program to Store Information of Students Using Structure
  • C Program to Store Data in Structures Dynamically
  • C Program to Write a Sentence to a File
  • C Program to Read the First Line From a File
  • C Program to Display its own Source Code as Output
  • C Program to Print Pyramids and Patterns
  • C Programming Home
  • ▼C Programming Exercises
  • Basic Declarations and Expressions
  • Basic Part-II
  • Basic Algorithm
  • Variable Type
  • Input - Output
  • Conditional Statements
  • Do-While Loop
  • Linked List
  • Callback function
  • Variadic function
  • Inline Function
  • File Handling
  • Searching and Sorting

C Programming Exercises, Practice, Solution : For Loop

C for loop [61 exercises with solution].

[ An editor is available at the bottom of the page to write and execute the scripts.   Go to the editor ]

1. Write a program in C to display the first 10 natural numbers. Expected Output : 1 2 3 4 5 6 7 8 9 10 Click me to see the solution

2. Write a C program to compute the sum of the first 10 natural numbers. Expected Output : The first 10 natural number is : 1 2 3 4 5 6 7 8 9 10 The Sum is : 55 Click me to see the solution

3. Write a program in C to display n terms of natural numbers and their sum. Test Data : 7 Expected Output : The first 7 natural number is : 1 2 3 4 5 6 7 The Sum of Natural Number upto 7 terms : 28 Click me to see the solution

4. Write a program in C to read 10 numbers from the keyboard and find their sum and average. Test Data : Input the 10 numbers : Number-1 :2 ... Number-10 :2 Expected Output : The sum of 10 no is : 55 The Average is : 5.500000 Click me to see the solution

5. Write a program in C to display the cube of the number up to an integer. Test Data : Input number of terms : 5 Expected Output : Number is : 1 and cube of the 1 is :1 Number is : 2 and cube of the 2 is :8 Number is : 3 and cube of the 3 is :27 Number is : 4 and cube of the 4 is :64 Number is : 5 and cube of the 5 is :125 Click me to see the solution

6. Write a program in C to display the multiplication table for a given integer. Test Data : Input the number (Table to be calculated) : 15 Expected Output : 15 X 1 = 15 ... ... 15 X 10 = 150 Click me to see the solution

7. Write a program in C to display the multiplier table vertically from 1 to n. Test Data : Input upto the table number starting from 1 : 8 Expected Output : Multiplication table from 1 to 8 1x1 = 1, 2x1 = 2, 3x1 = 3, 4x1 = 4, 5x1 = 5, 6x1 = 6, 7x1 = 7, 8x1 = 8 ... 1x10 = 10, 2x10 = 20, 3x10 = 30, 4x10 = 40, 5x10 = 50, 6x10 = 60, 7x10 = 70, 8x10 = 80 Click me to see the solution

8. Write a C program to display the n terms of odd natural numbers and their sum. Test Data Input number of terms : 10 Expected Output : The odd numbers are :1 3 5 7 9 11 13 15 17 19 The Sum of odd Natural Number upto 10 terms : 100 Click me to see the solution

9. Write a program in C to display a pattern like a right angle triangle using an asterisk.

The pattern like :

Click me to see the solution

10. Write a C program to display a pattern like a right angle triangle with a number.

11. Write a program in C to make such a pattern like a right angle triangle with a number which will repeat a number in a row.

12. Write a program in C to make such a pattern like a right angle triangle with the number increased by 1.

13. Write a program in C to make a pyramid pattern with numbers increased by 1. 1 2 3 4 5 6 7 8 9 10 Click me to see the solution

14. Write a C program to make such a pattern as a pyramid with an asterisk.

15. Write a C program to calculate the factorial of a given number. Test Data : Input the number : 5 Expected Output : The Factorial of 5 is: 120 Click me to see the solution

16. Write a C program to display the sum of n terms of even natural numbers. Test Data : Input number of terms : 5 Expected Output : The even numbers are :2 4 6 8 10 The Sum of even Natural Number upto 5 terms : 30 Click me to see the solution

17. Write a C program to make such a pattern like a pyramid with a number which will repeat the number in the same row.

18. Write a program in C to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]. Test Data : Input the Value of x :2 Input the number of terms : 5 Expected Output : the sum = -0.415873 Number of terms = 5 value of x = 2.000000 Click me to see the solution

19. Write a program in C to display the n terms of a harmonic series and their sum. 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n terms Test Data : Input the number of terms : 5 Expected Output : 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + Sum of Series upto 5 terms : 2.283334 Click me to see the solution

20. Write a C program to display the pattern as a pyramid using asterisks, with each row containing an odd number of asterisks.

21. Write a program in C to display the sum of the series [ 9 + 99 + 999 + 9999 ...]. Test Data : Input the number or terms :5 Expected Output : 9 99 999 9999 99999 The sum of the saries = 111105 Click me to see the solution

22. Write a program in C to print Floyd's Triangle.

23. Write a program in C to find the sum of the series [x - x^3 + x^5 + ......]. Test Data : Input the value of x :3 Input number of terms : 5 Expected Output : The sum is : 16.375000 Click me to see the solution

24. Write a program in C to find the sum of the series [ x - x^3 + x^5 + ......]. Test Data : Input the value of x :2 Input number of terms : 5 Expected Output : The values of the series: 2 -8 32 -128 512 The sum = 410 Click me to see the solution

25. Write a C program that displays the n terms of square natural numbers and their sum. 1 4 9 16 ... n Terms Test Data : Input the number of terms : 5 Expected Output : The square natural upto 5 terms are :1 4 9 16 25 The Sum of Square Natural Number upto 5 terms = 55 Click me to see the solution

26. Write a program in C to find the sum of the series 1 +11 + 111 + 1111 + .. n terms. Test Data : Input the number of terms : 5 Expected Output : 1 + 11 + 111 + 1111 + 11111 The Sum is : 12345 Click me to see the solution

27. Write a C program to check whether a given number is a 'Perfect' number or not. Test Data : Input the number : 56 Expected Output : The positive divisor : 1 2 4 7 8 14 28 The sum of the divisor is : 64 So, the number is not perfect. Click me to see the solution

28. Write a C program to find the 'Perfect' numbers within a given number of ranges. Test Data : Input the starting range or number : 1 Input the ending range of number : 50 Expected Output : The Perfect numbers within the given range : 6 28 Click me to see the solution

29. Write a C program to check whether a given number is an Armstrong number or not. Test Data : Input a number: 153 Expected Output : 153 is an Armstrong number. Click me to see the solution

30. Write a C program to find the Armstrong number for a given range of number. Test Data : Input starting number of range: 1 Input ending number of range : 1000 Expected Output : Armstrong numbers in given range are: 1 153 370 371 407 Click me to see the solution

31. Write a program in C to display a pattern like a diamond.

32. Write a C program to determine whether a given number is prime or not.  Test Data : Input a number: 13 Expected Output : 13 is a prime number. Click me to see the solution

33. Write a C program to display Pascal's triangle.  Test Data : Input number of rows: 5 Expected Output :

34. Write a program in C to find the prime numbers within a range of numbers. Test Data : Input starting number of range: 1 Input ending number of range : 50 Expected Output : The prime number between 1 and 50 are : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 Click me to see the solution

35. Write a program in C to display the first n terms of the Fibonacci series. Fibonacci series 0 1 2 3 5 8 13 ..... Test Data : Input number of terms to display : 10 Expected Output : Here is the Fibonacci series upto to 10 terms : 0 1 1 2 3 5 8 13 21 34 Click me to see the solution

36. Write a C program to display a such a pattern for n rows using a number that starts with 1 and each row will have a 1 as the first and last number.

37. Write a program in C to display a given number in reverse order. Test Data : Input a number: 12345 Expected Output : The number in reverse order is : 54321 Click me to see the solution

38. Write a C program to check whether a number is a palindrome or not. Test Data : Input a number: 121 Expected Output : 121 is a palindrome number. Click me to see the solution

39. Write a program in C to find the number and sum of all integers between 100 and 200 which are divisible by 9. Expected Output : Numbers between 100 and 200, divisible by 9 : 108 117 126 135 144 153 162 171 180 189 198 The sum : 1683 Click me to see the solution

40. Write a C program to display the pyramid pattern using the alphabet.

41. Write a program in C to convert a decimal number into binary without using an array. Test Data : Input a decimal number: 25 Binary number equivalent to said decimal number is: 0000000000000000000000000001 1001 Click me to see the solution

42. Write a C program to convert a binary number into a decimal number without using array, function and while loop. Test Data : Input a binary number :1010101 Expected Output : The Binary Number : 1010101 The equivalent Decimal Number : 85 Click me to see the solution

43. Write a C program to find the HCF (Highest Common Factor) of two numbers. Test Data : Input 1st number for HCF: 24 Input 2nd number for HCF: 28 Expected Output : HCF of 24 and 28 is : 4 Click me to see the solution

44. Write a C program to find the LCM of any two numbers using HCF. Test Data : Input 1st number for LCM: 15 Input 2nd number for LCM: 20 Expected Output : The LCM of 15 and 20 is : 60 Click me to see the solution

45. Write a program in C to find the LCM of any two numbers. Test Data : Input 1st number for LCM: 15 Input 2nd number for LCM: 20 Expected Output : The LCM of 15 and 20 is : 60 Click me to see the solution

46. Write a C program to convert a binary number into a decimal number using the math function. Test Data : Input the binary number :1010100 Expected Output : The Binary Number : 1010100 The equivalent Decimal Number is : 84 Click me to see the solution

47. Write a C program to check whether a number is a Strong Number or not. Test Data : Input a number to check whether it is Strong number: 15 Expected Output : 15 is not a Strong number. Click me to see the solution

48. Write a C program to find Strong Numbers within a range of numbers. Test Data : Input starting range of number : 1 Input ending range of number: 200 Expected Output : The Strong numbers are : 1 2 145 Click me to see the solution

49. Write a C program to find the sum of an A.P. series. Test Data : Input the starting number of the A.P. series: 1 Input the number of items for the A.P. series: 10 Input the common difference of A.P. series: 4 Expected Output : The Sum of the A.P. series are : 1 + 5 + 9 + 13 + 17 + 21 + 25 + 29 + 33 + 37 = 190 Click me to see the solution

50. Write a program in C to convert a decimal number into octal without using an array. Test Data : Enter a number to convert : 79 Expected Output : The Octal of 79 is 117. Click me to see the solution

51. Write a C program to convert an octal number to a decimal without using an array. Test Data : Input an octal number (using digit 0 - 7) :745 Expected Output : The Octal Number : 745 The equivalent Decimal Number : 485 Click me to see the solution

52. Write a C program to find the sum of the G.P. series. Test Data : Input the first number of the G.P. series: 3 Input the number or terms in the G.P. series: 5 Input the common ratio of G.P. series: 2 Expected Output : The numbers for the G.P. series: 3.000000 6.000000 12.000000 24.000000 48.000000 The Sum of the G.P. series : 93.000000 Click me to see the solution

53. Write a C program to convert a binary number to octal. Test Data : Input a binary number :1001 Expected Output : The Binary Number : 1001 The equivalent Octal Number : 11 Click me to see the solution

54. Write a program in C to convert an octal number into binary. Test Data : Input an octal number (using digit 0 - 7) :57 Expected Output : The Octal Number : 57 The equivalent Binary Number : 101111

55. Write a C program to convert a decimal number to hexadecimal. Test Data : Input any Decimal number: 79 Expected Output : The equivalent Hexadecimal Number : 4F Click me to see the solution

56. Write a program in C to check whether a number can be expressed as the sum of two prime. Test Data : Input a positive integer: 16 Expected Output : 16 = 3 + 13 16 = 5 + 11 Click me to see the solution

57. Write a C program to print a string in reverse order. Test Data : Input a string to reverse : Welcome Expected Output : Reversed string is: emocleW Click me to see the solution

58. Write a C program to find the length of a string without using the library function. Test Data : Input a string : welcome Expected Output : The string contains 7 number of characters. So, the length of the string welcome is : 7 Click me to see the solution

59. Write a C program to check the Armstrong number of n digits. Test Data : Input an integer : 1634 Expected Output : 1634 is an Armstrong number Click me to see the solution

60. Write a C program that takes user input and counts the number of characters until the end of the file. Test Data : Input characters : w3resource Expected Output : Input characters: On Linux systems and OS X EOF is CTRL+D. For Windows EOF is CTRL+Z. Number of Characters: 10 Click me to see the solution

61. Write a C program that takes input from the user and counts the number of uppercase and lowercase letters, as well as the number of other characters. Test Data : Input characters : w3resource Expected Output : Input characters: On Linux systems and OS X EOF is CTRL+D. For Windows EOF is CTRL+Z. Uppercase letters: 0 Lowercase letters: 9 Other characters: 1 Click me to see the solution

C Programming Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Follow us on Facebook and Twitter for latest update.

  • Weekly Trends and Language Statistics

C Programming Questions and Answers

C programming interview questions and answers.

Here you can find C Programming interview questions and answers for your placement interviews and entrance exam preparation.

Why should I learn to solve C Programming questions?

Learn and practise solving C Programming questions to enhance your skills so that you can clear interviews, competitive examinations, and various entrance tests (CAT, GATE, GRE, MAT, bank exams, railway exams, etc.) with full confidence.

Where can I get C Programming questions and answers with explanations?

IndiaBIX provides you with numerous C Programming questions and answers with explanations. Fully solved problems with detailed answer descriptions and explanations are given and will be easy to understand.

Where can I get C Programming MCQ interview questions and answers (objective type, multiple choice)?

Here you can find multiple-choice-type C Programming questions and answers for your interviews and entrance examinations. Objective-type and true-or-false-type questions are also given here.

How do I download C Programming questions in PDF format?

You can download C Programming quiz questions and answers as PDF files or eBooks.

How do I solve C Programming quiz problems?

You can easily solve all kinds of quiz questions based on C Programming by practising the given exercises, including shortcuts and tricks.

  • Declarations and Initializations
  • Control Instructions
  • Expressions
  • Floating Point Issues
  • C Preprocessor
  • Structures, Unions, Enums
  • Input / Output
  • Command Line Arguments
  • Bitwise Operators
  • Memory Allocation
  • Variable Number of Arguments
  • Complicated Declarations
  • Library Functions

Current Affairs

Interview questions, group discussions.

  • Data Interpretation
  • Verbal Ability
  • Verbal Test
  • Python Programming
  • C Programming
  • C++ ,   C#
  • Technical Interview
  • Placement Papers
  • Submit Paper

swayam-logo

Introduction to Programming in C

  • What is an algorithmic solution to the problem?
  • How do we translate the algorithm into C code?
  • How efficient is the code?
  • How maintainable is the code?
  • Attempting algorithmic solutions to problems
  • Designing and coding moderate sized programs running to the order of a few hundred lines of code, and
  • Reading, understanding and modifying code written by others.
--> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> --> -->

Note: This exam date is subject to change based on seat availability. You can check final exam date on your hall ticket.

Page Visits

Course layout, books and references, instructor bio.

c programming assignment questions

Prof. Satyadev Nandakumar

Course certificate.

  • Assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. 
  • ( All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments). 
  • Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam - out of 100
  • Proctored Exam score =50% of the proctored certification exam score out of 100

c programming assignment questions

DOWNLOAD APP

c programming assignment questions

SWAYAM SUPPORT

Please choose the SWAYAM National Coordinator for support. * :

Download Interview guide PDF

  • C Interview Questions

Download PDF

What is c language.

C programming language, the pioneer of programming languages, is a procedural programming language. Dennis Ritchie created it as a system programming language for writing operating systems. It is one of the most popular programming languages because of its structure, high-level abstraction, machine-independent feature, etc. and is a great starting point for anyone wanting to get into coding. 

C is also used a lot in low-level system programming, embedded systems, and hardware. It has also been heavily optimized over the years and is still used to write sophisticated software such as the FreeBSD operating system and the XNU kernel. Low-level memory access, a small collection of keywords, and a clean style are all qualities that make the C language excellent for system programmings, such as operating system or compiler development . 

C is a low-level programming language that can be directly interfaced with the processor. It offers minimal abstraction and maximal control, making it an attractive option for developers who want to write efficient code. 

In this article, you will get to know the latest C Interview Questions & Answers you could expect as a fresher, intermediate, and experienced candidate.

C Basic Interview Questions

1. why is c called a mid-level programming language.

C has characteristics of both assembly-level i.e. low-level and higher-level languages. So as a result, C is commonly called a middle-level language. Using C, a user can write an operating system as well as create a menu-driven consumer billing system.

c programming assignment questions

2. What are the features of the C language?

Some features of the C language are- 

  • It is Simple And Efficient. 
  • C language is portable or Machine Independent.
  • C is a mid-level Programming Language. 
  • It is a structured Programming Language.
  • It has a function-rich library. 
  • Dynamic Memory Management.
  • C is super fast.
  • We can use pointers in C.
  • It is extensible.

3. What is a token?

The individual elements of a program are called Tokens. There are following 6 types of tokens are available in C:

  • Identifiers
  • Special Characters

4. What is the use of printf() and scanf() functions? Also explain format specifiers?

  • printf() is used to print the output on the display.
  • scanf() is used to read formatted data from the keyboard. 

Some datatype format specifiers for both printing and scanning purposes are as follows:

  • %d : It's a datatype format specifier for printing and scanning an integer value. 
  • %s : It's a datatype format specifier for printing and scanning a string. 
  • %c : It's a datatype format specifier for displaying and scanning a character value.
  • %f : The datatype format specifier %f is used to display and scan a float value.

5. What's the value of the expression 5["abxdef"]?

The answer is 'f'.

Explanation: The string mentioned "abxdef" is an array, and the  expression is equal to "abxdef"[5]. Why is the inside-out expression equivalent?  Because a[b] is equivalent to *(a + b) which is equivalent to *(b + a) which is equivalent to b[a].

Learn via our Video Courses

6. what is a built-in function in c.

The most commonly used built-in functions in C are scanf(), printf(), strcpy, strlwr, strcmp, strlen, strcat, and many more.

Built-function is also known as library functions that are provided by the system to make the life of a developer easy by assisting them to do certain commonly used predefined tasks. For example, if you need to print output or your program into the terminal, we use printf() in C.

7. What is a Preprocessor?

A preprocessor is a software program that processes a source file before sending it to be compiled. Inclusion of header files, macro expansions, conditional compilation, and line control are all possible with the preprocessor.

c programming assignment questions

8. In C, What is the #line used for?

In C, #line is used as a preprocessor to re-set the line number in the code, which takes a parameter as line number. Here is an example for the same.

9. How can a string be converted to a number?

The function takes the string as an input that needs to be converted to an integer.

Return Value:

  • On successful conversion, it returns the desired integer value
  • If the string starts with alpha-numeric char or only contains alpha-num char, 0 is returned.
  • In case string starts with numeric character but is followed by alpha-num char, the string is converted to integer till the first occurrence of alphanumeric char.

c programming assignment questions

10. How can a number be converted to a string?

The function takes a pointer to an array of char elements that need to be converted, and a format string needs to be written in a buffer as a string

The output after running the above code:

Output: Value of Pi = 3.141593

11. What is recursion in C?

When a function in C calls a copy of itself, this is known as recursion. To put it another way, when a function calls itself, this technique is called Recursion. Also, this function is known as recursive function.

Syntax of Recursive Function:

12. Why doesn’t C support function overloading?

After you compile the C source, the symbol names need to be intact in the object code. If we introduce function overloading in our source, we should also provide name mangling as a preventive measure to avoid function name clashes. Also, as C is not a strictly typed language many things(ex: data types) are convertible to each other in C. Therefore, the complexity of overload resolution can introduce confusion in a language such as C.

When you compile a C source, symbol names will remain intact. If you introduce function overloading, you should provide a name mangling technique to prevent name clashes. Consequently, like C++, you'll have machine-generated symbol names in the compiled binary.

Additionally, C does not feature strict typing. Many things are implicitly convertible to each other in C. The complexity of overload resolution rules could introduce confusion in such kind of language

13. What is the difference between global int and static int declaration?

The difference between this is in scope. A truly global variable has a global scope and is visible everywhere in your program.

global_temp is a global variable that is visible to everything in your program, although to make it visible in other modules, you'd need an ”extern int global_temp; ” in other source files if you have a multi-file project.

A static variable has a local scope but its variables are not allocated in the stack segment of the memory. It can have less than global scope, although - like global variables - it resides in the .bss segment of your compiled binary.

14. What is a pointer in C?

A pointer is a variable that stores or points to another variable's address. The value of a variable is stored in a normal variable, whereas the address of a variable is stored in a pointer variable.

c programming assignment questions

15. Difference between const char* p and char const* p?

  • const char* p is a pointer to a const char.
  • char const* p is a pointer to a char const.

Since const char and char const are the same, it's the same.

16. What is pointer to pointer in C?

In C, a pointer can also be used to store the address of another pointer. A double pointer or pointer to pointer is such a pointer. The address of a variable is stored in the first pointer, whereas the address of the first pointer is stored in the second pointer.

The syntax of declaring a double pointer is given below:

17. Why n++ executes faster than n+1 ?

n++ being a unary operation, it just needs one variable. Whereas, n = n + 1 is a binary operation that adds overhead to take more time (also binary operation: n += 1). However, in modern platforms, it depends on few things such as processor architecture, C compiler, usage in your code, and other factors such as hardware problems.

While in the modern compiler even if you write n = n + 1 it will get converted into n++ when it goes into the optimized binary, and it will be equivalently efficient.

c programming assignment questions

18. What is typecasting in C?

Typecasting is the process to convert a variable from one datatype to another.  If we want to store the large type value to an int type, then we will convert the data type into another data type explicitly.

Syntax: (data_type)expression;

For Example:

19. What are the advantages of Macro over function?

Macro on a high-level copy-paste, its definitions to places wherever it is called. Due to which it saves a lot of time, as no time is spent while passing the control to a new function and the control is always with the callee function. However, one downside is the size of the compiled binary is large but once compiled the program comparatively runs faster.

20. What are Enumerations?

Enumeration, also known as Enum in C, is a user-defined data type. It consists of constant integrals or integers that have names assigned to them by the user. Because the integer values are named with enum in C, the whole program is simple to learn, understand, and maintain by the same or even different programmer.

21. When should we use the register storage specifier?

If a variable is used frequently, it should be declared with the register storage specifier, and the compiler may allocate a CPU register for its storage to speed up variable lookup.

C Intermediate Interview Questions

1. specify different types of decision control statements.

All statements written in a program are executed from top to bottom one by one. Control statements are used to execute/transfer the control from one part of the program to another depending on the condition.

  • normal if-else statement.
  • Else-if statement
  • nested if-else statement.
  • Switch statement.

2. What is an r-value and l-value?

  • The term "r-value" refers to a data value stored in memory at a given address. An r-value is an expression that cannot have a value assigned to it, hence it can only exist on the right side of an assignment operator(=).
  • The term "l-value" refers to a memory location that is used to identify an object. The l-value can be found on either the left or right side of an assignment operator(=). l-value is frequently used as an identifier.

3. What is the difference between malloc() and calloc()?

calloc() and malloc() are memory dynamic memory allocating functions. The main difference is that malloc() only takes one argument, which is the number of bytes, but calloc() takes two arguments, which are the number of blocks and the size of each block.

4. What is the difference between struct and union in C?

A struct is a group of complex data structures stored in a block of memory where each member on the block gets a separate memory location to make them accessible at once Whereas in the union, all the member variables are stored at the same location on the memory as a result to which while assigning a value to a member variable will change the value of all other members.

5. What is call by reference in functions?

When we caller function makes a function call bypassing the addresses of actual parameters being passed, then this is called call by reference. In incall by reference, the operation performed on formal parameters affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters.

6. What is pass by reference in functions?

In Pass by reference, the callee receives the address and makes a copy of the address of an argument into the formal parameter. Callee function uses the address to access the actual argument (to do some manipulation). If the callee function changes the value addressed at the passed address it will be visible to the caller function as well.

c programming assignment questions

7. What is a memory leak? How to avoid it?

When we assign a variable it takes space of our RAM (either heap or RAM)dependent on the size of data type, however, if a programmer uses a memory available on the heap and forgets to a delta it, at some point all the memory available on the ram will be occupied with no memory left this can lead to a memory leak.

To avoid memory leaks, you can trace all your memory allocations and think forward, where you want to destroy (in a good sense) that memory and place delete there. Another way is to use C++ smart pointer in C linking it to GNU compilers.

8. What is Dynamic memory allocation in C? Name the dynamic allocation functions.

C is a language known for its low-level control over the memory allocation of variables in DMA there are two major standard library malloc() and free. The malloc() function takes a single input parameter which tells the size of the memory requested It returns a pointer to the allocated memory. If the allocation fails, it returns NULL. The prototype for the standard library function is like this:

void *malloc(size_t size); The free() function takes the pointer returned by malloc() and de-allocates the memory. No indication of success or failure is returned. The function prototype is like this: 

void free(void *pointer); There are 4 library functions provided by C defined under <stdlib.h> header file to facilitate dynamic memory allocation in C programming. They are:

9. What is typedef?

typedef is a C keyword, used to define alias/synonyms for an existing type in C language. In most cases, we use typedef's to simplify the existing type declaration syntax. Or to provide specific descriptive names to a type.

typedef provides an alias name to the existing complex type definition. With typedef, you can simply create an alias for any type. Whether it is a simple integer to complex function pointer or structure declaration, typedef will shorten your code.

10. Why is it usually a bad idea to use gets()? Suggest a workaround.

The standard input library gets() reads user input till it encounters a new line character. However, it does not check on the size of the variable being provided by the user is under the maximum size of the data type which makes the system vulnerable to buffer overflow and the input being written into memory where it isn’t supposed to.

We, therefore, use gets() to achieve the same with a restricted range of input

Bonus: It remained an official part of the language up to the 1999 ISO C standard, but it was officially removed by the 2011 standard. Most C implementations still support it, but at least GCC issues a warning for any code that uses it.

11. What is the difference between #include "..." and #include <...>?

In practice, the difference is in the location where the preprocessor searches for the included file.

For #include <filename> the C preprocessor looks for the filename in the predefined list of system directories first and then to the directories told by the user(we can use -I option to add directories to the mentioned predefined list). 

For #include "filename" the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the #include <filename> form. This method is normally used to include programmer-defined header files.

12. What are dangling pointers? How are dangling pointers different from memory leaks?

The dangling pointer points to a memory that has already been freed. The storage is no longer allocated. Trying to access it might cause a Segmentation fault. A common way to end up with a dangling pointer:

You are returning an address that was a local variable, which would have gone out of scope by the time control was returned to the calling function. (Undefined behavior)

In the figure shown above writing to a memory that has been freed is an example of the dangling pointer, which makes the program crash.

A memory leak is something where the memory allocated is not freed which causes the program to use an undefined amount of memory from the ram making it unavailable for every other running program(or daemon) which causes the programs to crash. There are various tools like O profile testing which is useful to detect memory leaks on your programs.

13. What is the difference between ‘g’ and “g” in C?

In C double-quotes variables are identified as a string whereas single-quoted variables are identified as the character. Another major difference being the string (double-quoted) variables end with a null terminator that makes it a 2 character array.

14. Which is better #define or enum?

  • If we let it, the compiler can build enum values automatically. However, each of the defined values must be given separately.
  • Because macros are preprocessors, unlike enums, which are compile-time entities, the source code is unaware of these macros. So, if we use a debugger to debug the code, the enum is superior.
  • Some compilers will give a warning if we use enum values in a switch and the default case is missing.
  • Enum always generates int-type identifiers. The macro, on the other hand, allowed us to pick between various integral types.
  • Unlike enum, the macro does not have a defined scope constraint.

15. Suppose a global variable and local variable have the same name. Is it possible to access a global variable from a block where local variables are defined?

No. This isn’t possible in C. It’s always the most local variable that gets preference.

16. Which structure is used to link the program and the operating system?

The file structure is used to link the operating system and a program. The header file "stdio.h" (standard input/output header file) defines the file. It contains information about the file being used like its current size and its memory location. It contains a character pointer that points to the character which is currently being opened. When you open a file, it establishes a link between the program and the operating system about which file is to be accessed.

17. What is a near pointer and a far pointer in C?

  • Near Pointer : In general, the near pointer can be considered because it is used to hold the address, which has a maximum size of just 16 bits. We can't store an address with a size larger than 16 bits using the near pointer. All other smaller addresses that are within the 16-bit limit, on the other hand, can be stored. Because we can only access 64kb of data at a time, you might assume the 16 bits are insufficient. As a result, it is regarded as one of the near-pointer's biggest drawbacks, which is why it is no longer commonly used.
  • Far Pointer: A far pointer is considered a pointer of size 32 bits. It can, however, use the current segment to access information stored outside the computer's memory. Although, in order to use this type of pointer, we usually need to allocate the sector register to store the data address in the current segment.

C Interview Questions For Experienced

1. how can you remove duplicates in an array.

The following program will help you to remove duplicates from an array.

2. Can we compile a program without a main() function?

Yes, we can compile a program without main() function Using Macro.

3. Write a program to get the higher and lower nibble of a byte without using shift operator?

#include<stdio.h> struct full_byte { char first : 4; char second : 4; }; union A { char x; struct full_byte by; }; main() { char c = 100; union A a; a.x = c; printf("the two nibbles are: %d and %d\n", a.by.first, a.by.second); }

4. How do you override a defined macro?

To override a defined macro we can use #ifdef and #undef preprocessors as follows:

  • #define A 10

If macro A is defined, it will be undefined using undef and then defined again using define.

5. Write a C program to check if it is a palindrome number or not using a recursive method.

#include <stdio.h> #include <conio.h> int reverse(int num); int isPalindrome(int num); int main() { int num; printf("Enter a number: "); scanf("%d", &num); if(isPalindrome(num) == 1) { printf("the given number is a palindrome"); } else { printf("the given number is not a palindrome number"); } return 0; } int isPalindrome(int num) { if(num == reverse(num)) { return 1; } return 0; } int reverse(int num) { int rem; static int sum=0; if(num!=0){ rem=num%10; sum=sum*10+rem; reverse(num/10); } else return sum; return sum; }

6. C program to check the given number format is in binary or not.

#include<stdio.h> #include<conio.h> int main() { int j,num; printf("Please enter a number :"); scanf("%d",&num); while(num>0) { j=num%10; if( j!=0 && j!=1 ) { printf("num is not binary"); break; } num=num/10; if(num==0) { printf("num is binary"); } } getch(); }

7. C Program to find a sum of digits of a number using recursion.

#include<stdio.h> #include<conio.h> int sumOfDigits(int num) { static int sum = 0; int rem; sum = sum + (num%10); rem = num/10; if(rem > 0) { sumOfDigits(rem); } return sum; } int main() { int j,num; printf("Please enter a number :"); scanf("%d",&num); printf("sum of digits of the number = %d ",sumOfDigits(num)); getch(); }

8. Can you tell me how to check whether a linked list is circular?

Single Linked List

c programming assignment questions

Circular Linked List

Circular linked list is a variation of a linked list where the last node is pointing to the first node's information part. Therefore the last node does not point to null.

Algorithm to find whether the given linked list is circular

A very simple way to determine whether the linked list is circular or not

  • Traverse the linked list
  • Check if the node is pointing to the head.
  • If yes then it is circular.

Let's look at the snippet where we code this algorithm.

9. What is the use of a semicolon (;) at the end of every program statement?

It is majorly related to how the compiler reads( or parses) the entire code and breaks it into a set of instructions(or statements), to which semicolon in C acts as a boundary between two sets of instructions.

10. How to call a function before main()?

To call a function before the main(), pragma startup directive should be used. E.g.-

The output of the above program will be -

This pragma directive, on the other hand, is compiler-dependent. This is not supported by gcc. As a result, it will ignore the startup directive and produce no error. But the output, in that case, will be -

11. Differentiate between the macros and the functions.

The differences between macros and functions can be explained as follows:

Course Status : Completed
Course Type : Elective
Duration : 8 weeks
Category :
Credit Points : 2
Undergraduate/Postgraduate
Start Date : 14 Sep 2020
End Date : 06 Nov 2020
Enrollment Ends : 25 Sep 2020
Exam Date : 18 Dec 2020 IST
Macros Functions
It is preprocessed rather than compiled. It is compiled not preprocessed.
It is preprocessed rather than compiled. Function checks for compilation errors.
Code length is increased. Code length remains the same.
Macros are faster in execution. Functions are a bit slower in execution.
Macros are useful when a small piece of code is used multiple times in a program. Functions are helpful when a large piece of code is repeated a number of times.

12. Differentiate Source Codes from Object Codes

c programming assignment questions

The difference between the Source Code and Object Code is that Source Code is a collection of computer instructions written using a human-readable programming language while Object Code is a sequence of statements in machine language, and is the output after the compiler or an assembler converts the Source Code.

The last point about Object Code is the way the changes are reflected. When the Source Code is modified, each time the Source Code needs to be compiled to reflect the changes in the Object Code.

13. What are header files and what are its uses in C programming?

c programming assignment questions

In C header files must have the extension as .h, which contains function definitions, data type definitions, macro, etc. The header is useful to import the above definitions to the source code using the #include directive. For example, if your source code needs to take input from the user do some manipulation and print the output on the terminal, it should have stdio.h file included as #include <stdio.h>, with which we can take input using scanf() do some manipulation and print using printf().

14. When is the "void" keyword used in a function

The keyword “void” is a data type that literally represents no data at all. The most obvious use of this is a function that returns nothing:

Here we’ve declared a function, and all functions have a return type. In this case, we’ve said the return type is “void”, and that means, “no data at all” is returned.  The other use for the void keyword is a void pointer. A void pointer points to the memory location where the data type is undefined at the time of variable definition. Even you can define a function of return type void* or void pointer meaning “at compile time we don’t know what it will return” Let’s see an example of that.

15. What is dynamic data structure?

A dynamic data structure (DDS) refers to an organization or collection of data in memory that has the flexibility to grow or shrink in size, enabling a programmer to control exactly how much memory is utilized. Dynamic data structures change in size by having unused memory allocated or de-allocated from the heap as needed. 

Dynamic data structures play a key role in programming languages like C, C++, and Java because they provide the programmer with the flexibility to adjust the memory consumption of software programs.

16. Add Two Numbers Without Using the Addition Operator

For the sum of two numbers, we use the addition (+) operator. In these tricky C programs, we will write a C program to add two numbers without using the addition operator.

17. Subtract Two Number Without Using Subtraction Operator

The bitwise complement operator is used in this program. The bitwise complement of number ~y=-(y+1). So, expression will become x+(-(y+1))+1=x-y-1+1=x-y

18. Multiply an Integer Number by 2 Without Using Multiplication Operator

The left shift operator shifts all bits towards the left by a certain number of specified bits. The expression x<<1 always returns x*2. Note that the shift operator doesn’t work on floating-point values.

For multiple of x by 4, use x<<2. Similarly x<<3 multiply x by 8. For multiple of the number x by 2^n, use x<<n.

19. Check whether the number is EVEN or ODD, without using any arithmetic or relational operators

The bitwise and(&) operator can be used to quickly check the number is odd or even.

20. Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL

Assume that we have linked list 1 → 2 → 3 → Ø, we would like to change it to Ø ← 1 ← 2 ← 3.

While you travel the linked list, change the current node's next pointer to point to its previous element. reference to the previous nodes should be stored into a temp variable as shown so that we don’t lose track of the swapped node. You also need another pointer to store the next node before changing the reference. Also when we are done return the new head of the reversed list.

21. Check for Balanced Parentheses using Stack

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  • Open brackets must be closed by the same type of brackets.
  • Open brackets must be closed in the correct order.

Example 1:  Input: s = "()"  Output: true Example 2:  Input: s = "()[]{}"  Output: true Example 3:  Input: s = "(]"  Output: false

Below is the source code for C Program to Check for Balanced Parentheses using Stack which is successfully compiled and run on Windows System to produce desired output as shown below :

c programming assignment questions

22. Program to find n’th Fibonacci number

Fibonacci sequence is characterized by the fact that every number after the first two is the sum of the two preceding ones. For example, consider below sequence

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . .. and so on

Where in F{n} = F{n-1} + F{n-2} with base values F(0) = 0 and <code>F(1) = 1

Below is naive implementation for finding the nth member of the Fibonacci sequence

23. Write a program to find the node at which the intersection of two singly linked lists begins.

Let's take an example of the following two linked lists which intersect at node c1.

c programming assignment questions

  • Get count of the nodes in the first list, let count be c1.
  • Get count of the nodes in the second list, let count be c2.
  • Get the difference of counts d = abs(c1 – c2)
  • Now traverse the bigger list from the first node till d nodes so that from here onwards both the lists have an equal no of nodes
  • Then we can traverse both the lists in parallel till we come across a common node. (Note that getting a common node is done by comparing the address of the nodes)

24. Merge Two sorted Linked List

Merge two sorted linked lists and return them as a sorted list. The list should be made by splicing together the nodes of the first two lists.

c programming assignment questions

Runtime Complexity Linear, O(m + n) where m and n are lengths of both linked lists. 

Memory Complexity Constant, O(1)

Maintain a head and a tail pointer on the merged linked list. Then choose the head of the merged linked list by comparing the first node of both linked lists. For all subsequent nodes in both lists, you choose the smaller current node and link it to the tail of the merged list, moving the current pointer of that list one step forward.

You keep doing this while there are some remaining elements in both lists. If there are still some elements in only one of the lists, you link this remaining list to the tail of the merged list.

Initially, the merged linked list is NULL. Compare the value of the first two nodes and make the node with the smaller value the head node of the merged linked list. In this example, it is 4 from head1.

Since it’s the first and only node in the merged list, it will also be the tail. Then move head1 one step forward.

C is the foundational language from which practically all other languages are built. C is the programming language's base. For writing system applications, it is a very popular and frequently used language. Even if new languages have surpassed it in popularity, it remains one of the most popular programming languages. The C questions listed here will aid you in interviews as well as improve your learning. I hope you found these to be helpful!

Additional Interview Resources

  • C++ Interview Questions
  • Practice Coding
  • Difference Between C and C++
  • ​​​​Difference Between C and Java
  • Features of C Language
  • C Programming MCQs
  • Technical Interview Questions
  • Coding Interview Questions

In the switch statement, each case instance value must be _______?

During function call, Default Parameter Passing Mechanism is called as

The statement printf(“%d”, 10 ? 0 ? 5 : 1 : 12); will print?

What is the correct syntax to access the value of struct variable book{ price, page }?

Bitwise operators can operate upon?

Which is the correct syntax to declare constants in C?

A binary tree with 27 nodes has _______ null branches.

C variable cannot start with which of the following option

Which of the following data structures is linear type?

The number of binary trees that can be formed using 5 nodes are

  • Privacy Policy

instagram-icon

  • Practice Questions
  • Programming
  • System Design
  • Fast Track Courses
  • Online Interviewbit Compilers
  • Online C Compiler
  • Online C++ Compiler
  • Online Java Compiler
  • Online Javascript Compiler
  • Online Python Compiler
  • Interview Preparation
  • Java Interview Questions
  • Sql Interview Questions
  • Python Interview Questions
  • Javascript Interview Questions
  • Angular Interview Questions
  • Networking Interview Questions
  • Selenium Interview Questions
  • Data Structure Interview Questions
  • Data Science Interview Questions
  • System Design Interview Questions
  • Hr Interview Questions
  • Html Interview Questions
  • Amazon Interview Questions
  • Facebook Interview Questions
  • Google Interview Questions
  • Tcs Interview Questions
  • Accenture Interview Questions
  • Infosys Interview Questions
  • Capgemini Interview Questions
  • Wipro Interview Questions
  • Cognizant Interview Questions
  • Deloitte Interview Questions
  • Zoho Interview Questions
  • Hcl Interview Questions
  • Highest Paying Jobs In India
  • Exciting C Projects Ideas With Source Code
  • Top Java 8 Features
  • Angular Vs React
  • 10 Best Data Structures And Algorithms Books
  • Best Full Stack Developer Courses
  • Best Data Science Courses
  • Python Commands List
  • Data Scientist Salary
  • Maximum Subarray Sum Kadane’s Algorithm
  • Python Cheat Sheet
  • C++ Cheat Sheet
  • Javascript Cheat Sheet
  • Git Cheat Sheet
  • Java Cheat Sheet
  • Data Structure Mcq
  • C Programming Mcq
  • Javascript Mcq

1 Million +

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

NPTEL Assignment Answers and Solutions 2024 (July-Dec). Get Answers of Week 1 2 3 4 5 6 7 8 8 10 11 12 for all courses. This guide offers clear and accurate answers for your all assignments across various NPTEL courses

progiez/nptel-assignment-answers

Folders and files.

NameName
164 Commits

Repository files navigation

Nptel assignment answers 2024 with solutions (july-dec), how to use this repo to see nptel assignment answers and solutions 2024.

If you're here to find answers for specific NPTEL courses, follow these steps:

Access the Course Folder:

  • Navigate to the folder of the course you are interested in. Each course has its own folder named accordingly, such as cloud-computing or computer-architecture .

Locate the Weekly Assignment Files:

  • Inside the course folder, you will find files named week-01.md , week-02.md , and so on up to week-12.md . These files contain the assignment answers for each respective week.

Select the Week File:

  • Click on the file corresponding to the week you are interested in. For example, if you need answers for Week 3, open the week-03.md file.

Review the Answers:

  • Each week-XX.md file provides detailed solutions and explanations for that week’s assignments. Review these files to find the information you need.

By following these steps, you can easily locate and use the assignment answers and solutions for the NPTEL courses provided in this repository. We hope this resource assists you in your studies!

List of Courses

Here's a list of courses currently available in this repository:

  • Artificial Intelligence Search Methods for Problem Solving
  • Cloud Computing
  • Computer Architecture
  • Cyber Security and Privacy
  • Data Science for Engineers
  • Data Structure and Algorithms Using Java
  • Database Management System
  • Deep Learning for Computer Vision
  • Deep Learning IIT Ropar
  • Digital Circuits
  • Ethical Hacking
  • Introduction to Industry 4.0 and Industrial IoT
  • Introduction to Internet of Things
  • Introduction to Machine Learning IIT KGP
  • Introduction to Machine Learning
  • Introduction to Operating Systems
  • ML and Deep Learning Fundamentals and Applications
  • Problem Solving Through Programming in C
  • Programming DSA Using Python
  • Programming in Java
  • Programming in Modern C
  • Python for Data Science
  • Soft Skill Development
  • Soft Skills
  • Software Engineering
  • Software Testing
  • The Joy of Computation Using Python
  • Theory of Computation

Note: This repository is intended for educational purposes only. Please use the provided answers as a guide to better understand the course material.

📧 Contact Us

For any queries or support, feel free to reach out to us at [email protected] .

🌐 Connect with Progiez

Website

⭐️ Follow Us

Stay updated with our latest content and updates by following us on our social media platforms!

🚀 About Progiez

Progiez is an online educational platform aimed at providing solutions to various online courses offered by NPTEL, Coursera, LinkedIn Learning, and more. Explore our resources for detailed answers and solutions to enhance your learning experience.

Disclaimer: This repository is intended for educational purposes only. All content is provided for reference and should not be submitted as your own work.

Contributors 3

@raveshrawal

IMAGES

  1. C Language

    c programming assignment questions

  2. Introduction to C

    c programming assignment questions

  3. I need help with this C programming assignment. This

    c programming assignment questions

  4. Introduction to C

    c programming assignment questions

  5. C-Programming-Exam-Questions-List.pdf

    c programming assignment questions

  6. Solved Programming Assignment: Count Words Write a C++

    c programming assignment questions

VIDEO

  1. Assignment Operator in C Programming

  2. NPTEL Problem Solving Through Programming in C Week 0 Assignment Solution July 2024 |IIT Kharagpur

  3. Assignment Operator in C Programming

  4. Introduction to Programming in C Week 2 Assignment Answers 2024 |@OPEducore

  5. http://bit.ly/3HSre6L 🔥100%🔥💥Introduction to Programming In C Q2||WEEK-3 Assignment Answers|#NPTEL

  6. C programming and Data Structures Important questions CS3353 Feb 2024 Exam 4G Silver Academy

COMMENTS

  1. C Exercises

    This C Exercise page contains the top 30 C exercise questions with solutions that are designed for both beginners and advanced programmers. It covers all major concepts like arrays, pointers, for-loop, and many more. So, Keep it Up! Solve topic-wise C exercise questions to strengthen your weak topics.

  2. C programming Exercises, Practice, Solution

    C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs.

  3. C All Exercises & Assignments

    Write a C program to check whether number is positive, negative or zero . Description: You need to write a C program to check whether number is positive, negative or zero. Conditions: Create variable with name of number and the value will taken by user or console; Create this c program code using else if ladder statement

  4. C programming examples, exercises and solutions for beginners

    Matrix (2D array) Add two matrices. Scalar matrix multiplication. Multiply two matrices. Check if two matrices are equal. Sum of diagonal elements of matrix. Interchange diagonal of matrix. Find upper triangular matrix. Find sum of lower triangular matrix.

  5. Assignments

    This section provides the course assignments, supporting files, and solutions. Browse Course Material Syllabus Calendar Lecture Notes Labs ... assignment_turned_in Programming Assignments with Examples. Download Course. Over 2,500 courses & materials Freely sharing knowledge with learners and educators around the world.

  6. Practice C

    Improve your C programming skills with over 200 coding practice problems. Solve these beginner friendly problems online to get better at C language. ... Multiple Choice Question: Easy: Learning SQL: 339: Multiple Choice Question: Easy: Parking Charges: 416: 6. ... Variable Assignment : Easy: What is the output: Easy: Output The Difference - MCQ ...

  7. Basic programming exercises and solutions in C

    List of basic programming exercises. Write a C program to perform input/output of all basic data types. Write a C program to enter two numbers and find their sum. Write a C program to enter two numbers and perform all arithmetic operations. Write a C program to enter length and breadth of a rectangle and find its perimeter.

  8. Top 50 C Programming Interview Questions and Answers

    C Programming Interview Questions. C Programming language is one of the languages that are both complex yet important to learn for strengthening your programming skills. Interview questions can be categorized into two parts: ... An "l-value" will appear either on the right or left side of the assignment operator(=). An "r-value" is a ...

  9. Top 40 C Programming Theory Questions and Answers

    The document contains 24 questions and answers about C programming. Some key points covered include: - The main features of C like portability, modularity, flexibility and speed. - Basic data types in C like int, float, double, char and void. - Syntax errors occur due to mistakes in program syntax like incorrect commands or parameters. - Increment and decrement operators (++ and --) and how to ...

  10. C Exercises

    We have gathered a variety of C exercises (with answers) for each C Chapter. Try to solve an exercise by editing some code, or show the answer to see what you've done wrong. Count Your Score. You will get 1 point for each correct answer. Your score and total score will always be displayed.

  11. 200+ Interview Questions for C Programming

    Q17. Write a C program to swap two variables without using a third variable. This is one of the very common C interview questions. It can be solved in a total of five steps. For this, I have considered two variables as a and b, such that a = 5 and b = 10. #include<stdio.h>. int main(){. int a=5,b=10; a=b+a;

  12. C programming exercises: Function

    3. Write a program in C to swap two numbers using a function. Test Data : Input 1st number : 2 Input 2nd number : 4 Expected Output : Before swapping: n1 = 2, n2 = 4 After swapping: n1 = 4, n2 = 2. Click me to see the solution. 4. Write a program in C to check if a given number is even or odd using the function.

  13. C Programs

    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.

  14. C Programming Exercises With Solutions (PDF)

    Here you will get C Programming Exercises With Solutions. Here I am going to provide you a document of these, which you can download and make changes according to your own. Contents hide. 1 Download C Programming Practical Assignments Questions. 2 Download C Programming Exercises With Solutions PDF (2020)

  15. If else programming exercises and solutions in C

    Write a C program to find maximum between three numbers. Write a C program to check whether a number is negative, positive or zero. Write a C program to check whether a number is divisible by 5 and 11 or not. Write a C program to check whether a number is even or odd. Write a C program to check whether a year is leap year or not.

  16. Solve C

    Join over 23 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews. We use cookies to ensure you have the best browsing experience on our website. ... For Loop in C. Easy C (Basic) Max Score: 10 Success Rate: 93.79%. Solve Challenge. Sum of Digits of a Five Digit Number. Easy C ...

  17. C practical assignments questions

    Q 7 Write a program in c to transpose the given matrix. Submit Answer. View Solution. Q 8 Write a program in c to print only the diagonal elements of a matrix. Submit Answer. View Solution. c practical assignments questions to sharp your programming skills.

  18. Advanced C Programming

    C Assignments. A1: Write a program to check whether a given number is perfect or not. A2: Write a program to generate Fibonacci numbers less than equals to 'n'. A3: Write a program to print "Hello" in X format. A4: Write a program to read 3 numbers a, r, n, Generate AP, GP, HP. A5: Given the number from 1 to 365 , WAP to find which day of the year.

  19. C Examples

    Program. C Program to Print an Integer (Entered by the User) C Program to Add Two Integers. C Program to Multiply Two Floating-Point Numbers. C Program to Find ASCII Value of a Character. C Program to Compute Quotient and Remainder. C Program to Find the Size of int, float, double and char. C Program to Demonstrate the Working of Keyword long.

  20. C programming exercises: For Loop

    Write a C program to make such a pattern as a pyramid with an asterisk. * * * * * * * * * * Click me to see the solution. 15. Write a C program to calculate the factorial of a given number. Test Data : Input the number : 5 Expected Output: The Factorial of 5 is: 120 Click me to see the solution. 16. Write a C program to display the sum of n ...

  21. C Programming Questions and Answers

    You can easily solve all kinds of quiz questions based on C Programming by practising the given exercises, including shortcuts and tricks. Take an Online C Programming Test Now! C Programming questions and answers with explanations are provided for your competitive exams, placement interviews, and entrance tests.

  22. Introduction to Programming in C

    Assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. ( All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments). Unproctored programming exam score = 25% of the average scores obtained as part of Unproctored programming exam - out of 100

  23. Problems

    Boost your coding interview skills and confidence by practicing real interview questions with LeetCode. Our platform offers a range of essential problems for practice, as well as the latest questions being asked by top-tier companies. ... Interview. Store Study Plan. See all. Array 1722. String 717. Hash Table 621. Dynamic Programming 525. Math ...

  24. Top C Programming Interview Questions (2024)

    C Basic Interview Questions 1. Why is C called a mid-level programming language? C has characteristics of both assembly-level i.e. low-level and higher-level languages. So as a result, C is commonly called a middle-level language. Using C, a user can write an operating system as well as create a menu-driven consumer billing system.

  25. NPTEL Assignment Answers 2024 with Solutions (July-Dec)

    Locate the Weekly Assignment Files: Inside the course folder, you will find files named week-01.md, week-02.md, and so on up to week-12.md. These files contain the assignment answers for each respective week. Select the Week File: Click on the file corresponding to the week you are interested in.