C is a high-level, procedural programming language developed by Dennis M. Ritchie in 1972, primarily for UNIX system programming. It is known for its simplicity and efficiency, making it an ideal choice for beginners in programming. The document outlines the components of a C program, including header files, main method declaration, decision-making statements, loops, functions, arrays, pointers, and the ternary operator.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
29 views10 pages
Hmari File BNN Gyiii
C is a high-level, procedural programming language developed by Dennis M. Ritchie in 1972, primarily for UNIX system programming. It is known for its simplicity and efficiency, making it an ideal choice for beginners in programming. The document outlines the components of a C program, including header files, main method declaration, decision-making statements, loops, functions, arrays, pointers, and the ternary operator.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
WHAT IS C?
>» C is a generatpurpose, procedural, high-level programming language used in the
development of computer software and applications, system programming, dames, and
more.
> C language was developed by Dennis M. Ritchie at the Bell Telephone Laboratories
in 1972
> Itis a powerful and flexible language which was first developed for the programming of
the UNIX operating System.
> € 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.
* Components of a C Program
4.Header Files Inclusion — Line 1 [#include ]
The first and foremost component is the inclusion of the Header files in a C program. Some of
the C Header files:
+ stddef.h— Defines several useful types and macros.
+ stdint.h - Defines exact width integer types.
‘* _stdio.h - Defines core input and output functions
2. Main Method Declaration — Line 2 [int main()]
The next part of a C program is to declare the main() function. It is the entry point of a C
program and the execution typically begins with the first line of the main(). The empty brackets
indicate that the main doesn't take any parameter.
3. Body of Main Method — Line 3 to Line 6 [enclosed in {}]
The body of a function in the C program refers to statements that are a part of that function. It
can be anything like manipulations, searching, sorting, printing, ete. A pair of curly brackets
define the body of a function. All functions must start and end with curly brackets.
4. Statement - Line 4 [printf("Hello World’
‘Statements are the instructions given to the compiler. In C, a statement is always terminated
by a semicolon (;). In this particular case, we use printf() function to instruct the compiler to
display “Hello World’ text on the screen.
5. Return Statement — Line 5 [return 0;]
The last part of any C function is the return statement. The return statement refers to the
return values from a function. This return statement and return value depend upon the return
type of the function.
printtC-aa\n= proaict)
brinercosa\ne atrterence)DECISION MAKING STATEMENTSI(IF,|F ELSE,IF ELSE
IF,NESTED IF ELSE,SWITCH)
The conditional statements such as if, if else, switch, etc. are used for decision-making
purposes in C programs.
IF STATEMENT
he if statement is the most simple decision-making statement. It is used to decide whether a certain
statement or block of statements will be executed or rot ie if a certain condition is rue then a block of
statements is executed otherwise not
2.1F ELSE STATEMENT
The if statement alone tells us that if 2 condition is true it will execute a block of statements
and if the condition is false it won't. We can use the else statement with the if statement to
‘execute a block of code when the condition is false. The if-else statement consists of two
blocks, one for false expression and one for true expression.
* TO CHECK WHETHER THE NUMBER IS EVEN OR ODD
11 ontine € compiler to run € progran online tmp/soFS6kSe1L.0
#include enter value of 2
void mainc> .
‘ 4 4s even
printfCenter value of a\n">
scant("sa".a)
$fcan2--0)
‘
Brintf("%d 41s evena)
>
else
«
princt@-sa 1 eda a5
>
>
«+ TO FIND THE GREATER OF TWO NUMBERS3.IF ELSE IF STATEMENT
.As soon as one of the conditions controlling the if is true, the statement associated with that if
is executed, and the rest of the C else-if ladder is bypassed. If none of the conditions is true,
then the final else statement will be executed,
+ TO FIND GREATEST OF THREE NUMBERS
4. Switch Statement in C
The switch case statement is an alternative to the if else if ladder that can be used to execute
the conditional code based on the value of the variable specified in the switch statement.
* CALCULATOR
* TO FIND WHETHER THE ALPHABET IS CONSONANT OR VOWEL« C-Loop
Loops in programming are used to repeat a block of code until the specified
condition is met. A loop statement allows programmers to execute a statement or group of
statements multiple times without repetition of code.
FOR LOOP
For loop in C programming is a repetition control structure that allows programmers to write a
loop that will be executed a specific number of times.
2
3
5
10
2
+ TO PRINT N NUMBERS.
tincluse
4 void ming
<4
6 ima:
7 forcatiact0:as)
at
9 printtirxd (97.8)
>
+ SUM AND AVERAGE OF N NUMBERS,
11 online € compiler to run € progran online /mp/Yhawksinaya.o
include sum 55
ts.
void maint)
+4
For 4-14-10: 4+
4
>
Print #("sume Sd\n*.a):
teas:
printtgrtesa” tb:
>
+ FACTORIAL OF N NUMBERS
3 prinef(enter the value of n\n")* TO CHECK WHETHER THE GIVEN NUMBER IS PRIME OR NOT
Eo:
nt main) orizas
‘grantee he ner of elesents:)
9 Seonches amen)
M4 forcetskonberii)* TO PRINT THE PYRAMIDS USING FOR LOOP.
ve EE onto
tor J = 0: Fm At ge
‘ icCinter pyramia hetghe: “>
@ tor Geortnitiey
1° for (Soargen- ssi
" >
nll)
* WHILE LOOP
While loop does not depend upon the number of iterations. If the test condition will become false
then it will break from the while loop else body will be executed.
+ TO PRINT ARMSTRONG NUMBERS« C Functions
‘A function in C is a set of statements that when called perform some specific task.
Itis the basic building block of a C program that provides modularity and code
reusability. The programming statements of a function are enclosed within { }
braces, having certain meanings end performing certain operations. They are also
called subroutines or procedures in other languages.
+ TO CHECK WHETHER THE GIVEN NUMBER IS PRIME OR NOT USING
FUNCTIONS
meine <6 Shere EG | output
117 fbornact enter the value of numbers
2 include 5
3+ int addcint a, int b) The sum is: 9
4 return a+b
5)
6 Ant maine)
74
8 int nm
9 _printf(“enter the value of nunbers"):
10 seant crated” fm.)
11 int result = addcn.a):
12 printt(-te sum 4s: sa\n", result):
13 return 0;
a>
+ RECURSION IN C FUNCTION
Recursion is the process by which a function calls itself. C language allows writing of such
functions which call itself to solve complicated problems by breaking them down into simple and
easy problems. These functions are known as recursive functions.
111 fibonnack sum = 15
2 include
3 int nunbersuacint ny
at
5 af (nc 0) return 0:
6 return'n + pumbersum(n - 1):
7%
8 int maincy
ot
10 ant sun = numbersunc5):
11 printf("sun = $0", sum)
12 return 0;+ ARRAY INC
An array in C isa fixed-size collection of similar data items stored in contiguous memory
locations. Itcan be used to store the collection of primitive data types such as int, char, float,
etc... and also derived and user-defined data types such as pointers, structures, etc.
+ TO PRINT ARRAY
* TO COPY THE ELEMENTS OF ONE ARRAY
+ TO PRINT THE MAXIMUM ELEMENT OF ARRAY* TO PRINT THE MATRIX USING ARRAY
3 int main
soe maet91 0914.3
rorcare:s-s:3+)
«
we
” rorca-0:3-3:3++)
% praneteras *mart43t31):
« POINTERS INC
A pointer is defined as a derived data type that can store the address of other C variables or a
‘memory location. We
using pointers.
access and manipulate the data stored in that memory location
+ ACCESSING THE VALUE AND ADDRESS OF VARIABLE USING POINTERS.
4 Ane main
7 ranti("the value of variablests
Frinti(*the valve of var
ve ter
* POINTERS AND ARRAY
3 int maint
fe &
Sang num (47-(22.33.44..557
+ ined
o-
n>
3 >
the value of varisble:12
the value of varisble:12mine 2 S00 EEE ouput
1 // online C compiler to run C program online 25 75 135
2. #include
2) int maint)
a4
5 int num [4]={25,33,75,135}:
6 printf¢-%d ",*(num));
7 printf(-%d ".*(num2)):
8 printt(-%d *,“(nume3)):
8 return 0:
wy
« TERNANRY OPERATOR
Conditional Operator (? )
‘The conditional operator is the only ternary operator in C.
Here, Expression1 is the condition to be evaluated. If the condition(Expressiont) is True
then we will execute and return the result of Expression? otherwise if the
condition(Expression1) is false then we will execute and retum the result of Expression3.
mane S80 EEE one:
1.11 ternary operator enter the no 5 675 67
2 include greatest no7
3 int min()
ak
Sint a.be
6 int largest:
7 pranctcventer tne no")
8 scanf("Sd Xa Sd", 4a, 4b. Be);
9 largest=(arbaianc)?a: (boatib>c)?b:c:
10 orintfe-areatest noid", largest)
M1 return 0:
2a