Introduction to C Programming Language
Introduction to C Programming Language
Despite being over five decades old, C remains highly relevant. It is widely used in
embedded systems, system programming, operating systems, and game development.
Its simplicity and control over hardware make it a preferred language for beginners as
well as professional developers.
Merits of C (Advantages)
Demerits of C (Disadvantages)
1. Simple and Efficient: C has a small set of keywords and easy syntax.
2. Structured Language: Encourages modular programming.
3. Fast and Powerful: Close to hardware, fast execution.
4. Portable: Code can run on various hardware with minor changes.
5. Rich Library Support: Built-in functions for complex tasks.
6. Memory Management: Manual control of memory using functions like malloc()
and free().
Fundamentals of C Language
Character Set
C uses a defined set of characters for writing programs:
Letters: AZ, az
Digits: 09
Special Symbols: + / = % & ^ ! @ $ _ { } [ ] ; , . < > etc.
Whitespace Characters: Space, tab, newline
Tokens
Tokens are the smallest building blocks of a C program. They include:
Keywords: Reserved words (e.g., int, return, if, while)
Identifiers: User defined names for variables, functions, arrays, etc.
Constants: Fixed values like numbers or characters (e.g., 5, 'a', 3.14)
Strings: Sequence of characters inside double quotes (e.g., "Hello")
Operators: Symbols to perform operations (e.g., +, , , /, =)
Separators: Symbols like ;, {}, (), [] used to separate statements.
Data Types
Primary Data Types: int, float, char, double
Derived Data Types: Arrays, Pointers, Functions
User Defined Types: struct, union, Enum, typedef
Variables
A variable is a named location used to store data.
Example:
c
int age = 16.
Operators
Arithmetic Operators: + , /, %
Relational Operators: ==, !=, >, <, >=, <=
Logical Operators: &&, ||,!
Assignment Operators: =, +=, =, etc.
Control Structures
Used to control the flow of program execution:
Conditional Statements: if, if else, switch
Loops: for, while do while
Jump Statements: break, continue, goto, return
include <stdio.h>
int main() {
int a = 10, b = 20, sum;
sum = a + b;
printf("The sum is: %d\n", sum);
return 0;
}
include <stdio.h>
int main() {
int num1 = 29, num2 = 5, remainder;
remainder = num1 % num2;
printf("The remainder is: %d\n", remainder);
return 0;
}
include <stdio.h>
int main() {
float km = 3.5;
float meters = km 1000;
printf("%.2f km is %.2f meters\n", km, meters);
return 0;
}
include <stdio.h>
int main() {
float radius = 7.0;
float pi = 3.1416;
float area = pi radius radius;
printf("Area of the circle is: %.2f\n", area);
return 0;
}
include <stdio.h>
int main() {
float principal = 1000, rate = 5, time = 2;
float interest = (principal rate time) / 100;
printf("Simple Interest is: %.2f\n", interest);
return 0;
}
include <stdio.h>
int main() {
float celsius = 25, fahrenheit;
fahrenheit = (celsius 9 / 5) + 32;
printf("%.2f °C is %.2f °F\n", celsius, fahrenheit);
return 0;
}
Selection
include <stdio.h>
int main() {
int num = 10;
if (num > 0)
printf("The number is positive.\n");
return 0;
}
include <stdio.h>
int main() {
int num = -5;
if (num >= 0)
printf("The number is non-negative.\n");
else
printf("The number is negative.\n");
return 0;
}
include <stdio.h>
int main() {
int marks = 75;
include <stdio.h>
int main() {
int day = 3;
switch(day) {
case 1:
printf("Sunday\n");
break;
case 2:
printf("Monday\n");
break;
case 3:
printf("Tuesday\n");
break;
default:
printf("Other day\n");
}
return 0;
}
Single lopop
include <stdio.h>
int main() {
int i;
for(i = 1; i <= 10; i++) {
printf("%d ", i);
}
return 0;
}
Ntural
include <stdio.h>
int main() {
int n = 10, sum = 0, i;
for(i = 1; i <= n; i++) {
sum += i;
}
printf("Sum = %d\n", sum);
return 0;
}
Nested
include <stdio.h>
int main() {
int i, j;
for(i = 1; i <= 5; i++) {
for(j = 1; j <= 5; j++) {
printf(" ");
}
printf("\n");
}
return 0;
}
Mtulipclation
include <stdio.h>
int main() {
int i, j;
for(i = 1; i <= 5; i++) {
for(j = 1; j <= 10; j++) {
printf("%d x %d = %d\n", i, j, i j);
}
printf("\n");
}
return 0;
}
Factorial
include <stdio.h>
int main() {
int n, i, fact = 1;
printf("Enter number: ");
scanf("%d", &n);
Prime
include <stdio.h>
int main() {
int n, i, count = 0;
printf("Enter a number: ");
scanf("%d", &n);
if(n <= 1) {
printf("Neither Prime nor Composite");
} else {
for(i = 1; i <= n; i++) {
if(n % i == 0)
count++;
}
if(count == 2)
printf("Prime number");
else
printf("Composite number");
}
return 0;
}
Palindrome
include <stdio.h>
int main() {
int n, r, rev = 0, temp;
printf("Enter number: ");
scanf("%d", &n);
temp = n;
while(n != 0) {
r = n % 10;
rev = rev 10 + r;
n = n / 10;
}
if(temp == rev)
printf("Palindrome");
else
printf("Not palindrome");
return 0;
}
Fibonacci
include <stdio.h>
int main() {
int n, i, a = 0, b = 1, c;
printf("How many terms? ");
scanf("%d", &n);
return 0;
}
Introduction to Web Technology
Web technology refers to the tools, techniques, and languages used to build and
maintain websites and web applications. It includes front-end and back-end
development, database management, web design, and more. It allows users to interact
with content over the internet using browsers.
Language:
o HTML (HyperText Markup Language)
o CSS (Cascading Style Sheets)
o JavaScript
o PHP (Hypertext Preprocessor)
o Python
Frameworks:
o react.js
o Angular
o Django
o Laravel
o Node.js
Databases:
MySQL
MongoDB
PostgreSQL
Firebase
SQLite
---
---
---
---
Example:
```html
<form action="/submit" method="post">
<input type="text" name="name"><br>
<input type="email" name="email"><br>
</form>
```
10 Form Elements:
Text Field: `<input type="text">`
Password Field: `<input type="password">`
Radio Button: `<input type="radio" name="gender">`
Checkbox: `<input type="checkbox">`
Textarea: `<textarea></textarea>`
Dropdown List: `<select><option>Option</option></select>`
Submit Button: `<input type="submit">`
Reset Button: `<input type="reset">`
Email Field: `<input type="email">`
File Upload: `<input type="file">`
---
---
---
---
---