C Programming
C Programming
UNIT I
Presented By
Mrs.S.Geethamani
Assistant Professor
Dept. of Computer Application
Sri Ramakrishna College of Arts & Science for
Women,
CBE
Overview
1. Introduction
Basic Structure of C
C Tokens
Keywords & Identifiers
Constants & Variables
Data Types & Declarations
2. Managing Input & Output
Input / Output Functions
Operators
3. Operators & Expressions
4. Decision Making & Branching
IF Statements (Types)
Switch Statement
GOTO Statement
what is
programming
The process of creating a set of instructions
that tell a computer how to perform a specific
task or solve a problem
Introduction
C Programming
• C is a middle level procedural programming language.
• developed by Dennis Ritchie in 1972 at Bell Laboratories of
AT&T Labs to build the UNIX operating system.
• It provides low-level memory access, high performance, and
portability.
Our Mission
• C has evolved through standards like ANSI C, C99, C11, and
C23.
• it remains widely used in operating systems, embedded
systems, compilers, databases, networking, game engines,
and real-time systems for its efficiency and hardware-level
control.
Structure of the
C program
#include <stdio.h>
int main()
{
// Our first basic program in C
printf("Hello World!\n\n");
return 0;
}
C program to
Right-Angled Triangle Square
display your name
of * of *
and address
#include <stdio.h>
#include <stdio.h> #include <stdio.h>
int main() {
int main() { int main() {
// Display Name and
Address printf("*\n"); printf("* * * * *\
printf("Name : John printf("* *\n"); n");
Doe\n"); printf("* * *\n"); printf("* * * * *\
printf("Address: 123, printf("* * * *\n"); n");
Main Street, Cityville\n"); printf("* * * * *\ printf("* * * * *\
n"); n");
return 0;
return 0; printf("* * * * *\
} n");
}
printf("* * * * *\
Keywords in C
• Keywords are reserved words in C with predefined
meanings.
• You cannot use them as variable names or identifiers.
Identifiers in
C
• Identifiers are the names you give to variables,
functions, arrays, etc.
• You define them.
Example
String Constants
• Sequence of characters enclosed in double
quotes
• Examples: "Hello", "123", "C Programming"
Enumeration
Constants
• Named integer constants declared using enum
Data types in C
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old.\n",
age);
return 0;
}
Operators and
AGENDA
Expressions
#include <stdio.h>
int main() {
int a, b, max;
return 0;
Decision Making and
Branching
What is Decision Making
Decision making and branching in programming
allow a program to execute different blocks of
code based on specific conditions.
Decision Making and
Branching
Types of IF
statements
IF statements
in C
#include <stdio.h>
#include<conio.h>
void main()
{
int age = 18; OUTPUT
if (age >= 18)
printf("You are You are eligible to
eligible to vote."); vote.
getch();
}
IF-ELSE
Statement
It provides an alternative block of code to
execute when the if condition is false.
Example 1:
#include <stdio.h>
#include<conio.h>
void main()
{
int age = 15;
if (age >= 18)
{
printf("You are eligible to OUTPUT
vote.");
}
You are not eligible to
else
printf("You are not eligible to vote.
vote.");
}
Else-if ladder
or SYNTAX:
#include <stdio.h>
int main() {
int number1, number2;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
return 0;
Nested if-else
Statement
This involves placing an if or if-else statement inside
another if or else block. This allows for more complex
decision-making based on multiple levels of conditions.
Syntax
if (outer_condition)
{
if (inner_condition)
{
// Code for both conditions true
}
else
{
// Code for outer_condition true,
inner_condition false
}
}
else
{
// Code for outer_condition false
}
#include <stdio.h> Example Program
int main() {
int marks;
switch (expression)
{
case value1:
// code to execute if expression == value1
break;
case value2:
// code to execute if expression == value2
break;
...
default:
// code to execute if no case matches
EXAMPLE PROGRAM
#include <stdio.h>
int main() {
return 0;
QUIZ TIME