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, course description.
You are leaving MIT OpenCourseWare
- 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
- C Programming Tutorial
- C - Overview
- C - Features
- C - History
- C - Environment Setup
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- C - Functions
- C - Main Functions
- C - Return Statement
- C - Recursion
- C - Scope Rules
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- C - Pointers
- C - Pointer Arithmetics
- C - Passing Pointers to Functions
- C - Strings
- C - Array of Strings
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Pointers to Structures
- C - Self-Referential Structures
- C - Nested Structures
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
Assignment Operators in C
In C, the assignment operator stores a certain value in an already declared variable. A variable in C can be assigned the value in the form of a literal, another variable or an expression. The value to be assigned forms the right hand operand, whereas the variable to be assigned should be the operand to the left of = symbol, which is defined as a simple assignment operator in C. In addition, C has several augmented assignment operators.
The following table lists the assignment operators supported by the C language −
Simple assignment operator (=)
The = operator is the most frequently used operator in C. As per ANSI C standard, all the variables must be declared in the beginning. Variable declaration after the first processing statement is not allowed. You can declare a variable to be assigned a value later in the code, or you can initialize it at the time of declaration.
You can use a literal, another variable or an expression in the assignment statement.
Once a variable of a certain type is declared, it cannot be assigned a value of any other type. In such a case the C compiler reports a type mismatch error.
In C, the expressions that refer to a memory location are called "lvalue" expressions. A lvalue may appear as either the left-hand or right-hand side of an assignment.
On the other hand, the term rvalue refers to a data value that is stored at some address in memory. A rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.
Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side. Take a look at the following valid and invalid statements −
Augmented assignment operators
In addition to the = operator, C allows you to combine arithmetic and bitwise operators with the = symbol to form augmented or compound assignment operator. The augmented operators offer a convenient shortcut for combining arithmetic or bitwise operation with assignment.
For example, the expression a+=b has the same effect of performing a+b first and then assigning the result back to the variable a.
Similarly, the expression a<<=b has the same effect of performing a<<b first and then assigning the result back to the variable a.
Here is a C program that demonstrates the use of assignment operators in C:
When you compile and execute the above program, it produces the following result −
C Data Types
- C Operators
- C Input and Output
- C Control Flow
- C Functions
- C Preprocessors
C File Handling
- C Cheatsheet
C Interview Questions
C programming language tutorial.
- C Language Introduction
- Features of C Programming Language
- C Programming Language Standard
- C Hello World Program
- Compiling a C Program: Behind the Scenes
- Tokens in C
- Keywords in C
C Variables and Constants
- C Variables
- Constants in C
- Const Qualifier in C
- Different ways to declare variable as constant in C
- Scope rules in C
- Internal Linkage and External Linkage in C
- Global Variables in C
- Data Types in C
- Literals in C
- Escape Sequence in C
- Integer Promotions in C
- Character Arithmetic in C
- Type Conversion in C
C Input/Output
- Basic Input and Output in C
- Format Specifiers in C
- printf in C
- Scansets in C
- Formatted and Unformatted Input/Output functions in C with Examples
- Operators in C
- Arithmetic Operators in C
- Unary operators in C
- Relational Operators in C
- Bitwise Operators in C
- C Logical Operators
- Assignment Operators in C
- Increment and Decrement Operators in C
- Conditional or Ternary Operator (?:) in C
- sizeof operator in C
- Operator Precedence and Associativity in C
C Control Statements Decision-Making
- Decision Making in C (if , if..else, Nested if, if-else-if )
- C - if Statement
- C if...else Statement
- C if else if ladder
- Switch Statement in C
- Using Range in switch Case in C
- while loop in C
- do...while Loop in C
- For Versus While
- Continue Statement in C
- Break Statement in C
- goto Statement in C
- User-Defined Function in C
- Parameter Passing Techniques in C
- Function Prototype in C
- How can I return multiple values from a function?
- main Function in C
- Implicit return type int in C
- Callbacks in C
- Nested functions in C
- Variadic functions in C
- _Noreturn function specifier in C
- Predefined Identifier __func__ in C
- C Library math.h Functions
C Arrays & Strings
- Properties of Array in C
- Multidimensional Arrays in C
- Initialization of Multidimensional Array in C
- Pass Array to Functions in C
- How to pass a 2D array as a parameter in C?
- What are the data types for which it is not possible to create an array?
- How to pass an array by value in C ?
- Strings in C
- Array of Strings in C
- What is the difference between single quoted and double quoted declaration of char array?
- C String Functions
- Pointer Arithmetics in C with Examples
- C - Pointer to Pointer (Double Pointer)
- Function Pointer in C
- How to declare a pointer to a function?
- Pointer to an Array | Array Pointer
- Difference between constant pointer, pointers to constant, and constant pointers to constants
- Pointer vs Array in C
- Dangling, Void , Null and Wild Pointers in C
- Near, Far and Huge Pointers in C
- restrict keyword in C
C User-Defined Data Types
- C Structures
- dot (.) Operator in C
- Structure Member Alignment, Padding and Data Packing
- Flexible Array Members in a structure in C
- Bit Fields in C
- Difference Between Structure and Union in C
- Anonymous Union and Structure in C
- Enumeration (or enum) in C
C Storage Classes
- Storage Classes in C
- extern Keyword in C
- Static Variables in C
- Initialization of static variables in C
- Static functions in C
- Understanding "volatile" qualifier in C | Set 2 (Examples)
- Understanding "register" keyword in C
C Memory Management
- Memory Layout of C Programs
- Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
- Difference Between malloc() and calloc() with Examples
- What is Memory Leak? How can we avoid?
- Dynamic Array in C
- How to dynamically allocate a 2D array in C?
- Dynamically Growing Array in C
C Preprocessor
- C Preprocessor Directives
- How a Preprocessor works in C?
- Header Files in C
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- How to write your own header file in C?
- Macros and its types in C
- Interesting Facts about Macros and Preprocessors in C
- # and ## Operators in C
- How to print a variable name in C?
- Multiline macros in C
- Variable length arguments for Macros
- Branch prediction macros in GCC
- typedef versus #define in C
- Difference between #define and const in C?
- Basics of File Handling in C
- C fopen() function with Examples
- EOF, getc() and feof() in C
- fgets() and gets() in C language
- fseek() vs rewind() in C
- What is return type of getchar(), fgetc() and getc() ?
- Read/Write Structure From/to a File in C
- C Program to print contents of file
- C program to delete a file
- C Program to merge contents of two files into a third file
- What is the difference between printf, sprintf and fprintf?
- Difference between getc(), getchar(), getch() and getche()
Miscellaneous
- time.h header file in C with Examples
- Input-output system calls in C | Create, Open, Close, Read, Write
- Signals in C language
- Program error signals
- Socket Programming in C
- _Generics Keyword in C
- Multithreading in C
- C Programming Interview Questions (2024)
- Commonly Asked C Programming Interview Questions | Set 1
- Commonly Asked C Programming Interview Questions | Set 2
- Commonly Asked C Programming Interview Questions | Set 3
In this C Tutorial , you’ll learn all C programming basic to advanced concepts like variables, arrays, pointers, strings, loops, etc. This C Programming Tutorial is designed for both beginners as well as experienced professionals, who’re looking to learn and enhance their knowledge of the C programming language.
C is a general-purpose, procedural, high-level programming language used in the development of computer software and applications, system programming, games, and more.
- C language was developed by Dennis M. Ritchie at the Bell Telephone Laboratories in 1972 .
- It is a powerful and flexible language which was first developed for the programming of the UNIX operating System .
- C is one of the most widely used programming languages.
C programming language is known for its simplicity and efficiency. It is the best choice to start with programming as it gives you a foundational understanding of programming.
Print Hello World using C Programming
“Give this C code a try, and here’s a fun challenge: print ‘Hello World’ along with your name!”
Getting Started With C Programming Tutorial
Start your coding adventure with our free C Tutorial. A perfect C programming tutorial for beginners and advanced coders alike, this tutorial is your key to unlocking the magic of C programming. With clear explanations and fun examples.
C Arrays & Strings
C error handling.
- Setting Up C Development Environment
- C Identifiers
- Different Ways to Declare Variable as Constant in C
- Scope Rules in C
- Data Type Modifiers in C
C Input/Output Basic Input and Output in C Format Specifiers in C printf in C scanf in C Scansets in C Formatted and Unformatted Input and Output Functions C Operators
- Unary Operators in C
- Logical Operators in C
- size of Operator in C
- Decision-Making in C
- C if Statement
- C if…else Statement
- C if-else-if Ladder
- Using Range in switch case in C
- while looping in C
- do…while Loop in C
- for versus while Loop
- continue Statement in C
- break Statement in C
- Importance of Function Prototype in C
- Return Multiple Values From a Function
- Implicit Return Type int in C
- Nested Functions in C
- _Noreturn Function Specifier in C
- Maths Functions in C
- Initialization of Multidimensional Arrays in C
- Pass a 2D Array as a Parameter in C
- Data Types for Which Array is Not Possible
- Pass an Array by Value in C
- An Array of Strings in C
- Difference Between Single Quoted and Double Quoted Initialization
- String Functions in C
- Pointer Arithmetics in C
- Pointer to Pointer (Double Pointer) in C
- Declare Function Pointer in C
- Pointer to an Array in C
- Constant Pointer in C
- Dangling, Void, Null and Wild Pointers
- restrict Keyword in C
- Flexible Array Members in a Structure in C
- Initialization of Static Variables in C
- Static Functions in C
- Understanding “volatile” Qualifier in C
- Understanding the “register” Keyword in C
- Dynamic Memory Allocation in C
- Difference Between malloc() and calloc()
- What is a Memory Leak?
- Dynamically Allocate a 2D Array in C
- How a Preprocessor Works in C?
- Difference Between Header Files “stdio.h” and “stdlib.h”
- Write Your Own Header File in C
- Macros and their Types in C
- Interesting Facts About Macros and Preprocessors in C
- Print a Variable Name in C
- Multiline Macros in C
- Variable Length Arguments for Macros
- Branch Prediction Macros in GCC
- Difference Between #define and const in C
- C fopen() Function
- fgets() and gets() in C
- Return Type of getchar(), fgetc() and getc()
- C Program to Print Contents of File
- C Program to Delete a File
- C Program to Merge Contents of Two Files into a Third File
- Difference Between printf, sprintf and fprintf
- Difference Between getc(), getchar(), getch() and getche()
- Error Handling in C
- Using goto for Exception Handling in C
- Error Handling During File Operations in C
- C Program to Handle Divide By Zero and Multiple Exceptions
- Basic C Programs
- Control Flow Programs
- Pattern Printing Programs
- Functions Programs
- Arrays Programs
- Strings Programs
- Conversions Programs
- Pointers Programs
- Structures and Unions Programs
- File I/O Programs
- Date and Time Programs
- More C Programs
- Date and Time in C
- Input-output system calls in C
- Signals in C
- Program Error Signals in C
Top 50 C Programming Interview Questions and Answers Commonly Asked C Programming Interview Questions | Set 1 Commonly Asked C Programming Interview Questions | Set 2 Commonly Asked C Programming Interview Questions | Set 3
Why Learn C?
C programming language is one of the most popular programming language. It is a must learn for software engineering students. C is called the mother of all modern programming languages so learning C will help you to learn other languages easily like Java, C++, C#, Python, etc. C language is faster than other programming languages like Java and Python. It can handle low-level programming and we can compile the C code in a variety of computer platforms.
List of some key advantages of C language :
- Easy to learn.
- Versatile Language, which can be used in both applications and technologies.
- Mid-Level Programming Language.
- Structured Programming Language.
C compiler is a software that translates human-readable C language code into machine code or an intermediate code that can be executed by a computer’s central processing unit (CPU).
There are many C compilers available in the market, such as GNU Compiler Collection (GCC) , Microsoft Visual C++ Compiler , Clang , Intel C++ Compiler , and TinyCC (TCC) .
For this tutorial, we will be using the GNU-based online C compiler provided by GeeksforGeeks which is developed for beginners and is very easy to use compared to other compiler/IDE’s available on the web.
Features of C Language
There are some key features of C language that show the ability and power of C language:
- Simplicity and Efficiency: The simple syntax and structured approach make the C language easy to learn.
- Fast Speed: C is one of the fastest programming language because C is a static programming language, which is faster than dynamic languages like JavaScript and Python. C is also a compiler-based which is the reason for faster code compilation and execution.
- Portable: C provides the feature that you write code once and run it anywhere on any computer. It shows the machine-independent nature of the C language.
- Memory Management: C provides lower level memory management using pointers and functions like realloc(), free(), etc.
- Pointers: C comes with pointers. Through pointers, we can directly access or interact with the memory. We can initialize a pointer as an array, variables, etc.
- Structured Language: C provides the features of structural programming that allows you to code into different parts using functions which can be stored as libraries for reusability.
Applications of C Language
C was used in programs that were used in making operating systems. C was known as a system development language because the code written in C runs as fast as the code written in assembly language.
The use of C is given below:
- Operating Systems
- Language Compilers
- Text Editors
- Print Spoolers
- Network Drivers
- Modern Programs
- Language Interpreters
FAQs on C Language
Q1. how to learn c easily.
Answer:
The first steps towards learning C or any language are to write a hello world program. It gives the understanding of how to write and execute a code. After this, learn the following: Variables Operators Conditionals Loops and Errors Arrays and Strings Pointers and Memory Functions Structures Recursions
Q2. Difference between C and C++?
q3. is c easy to learn for beginners.
While C is one of the easy languages, it is still a good first language choice to start with because almost all programming languages are implemented in it. It means that once you learn C language, it’ll be easy to learn more languages like C++, Java, and C#.
Q4. Why should we learn C first rather than C++?
C is a ‘ mother of all languages .’ It provides a solid understanding of fundamental programming concepts and is considered easier to grasp. C offers versatile applications, from software development to game programming, making it an excellent choice for building a strong programming foundation.
Please Login to comment...
Related articles.
IMAGES
VIDEO