The document provides an overview of fundamental programming concepts in C language. It begins by comparing the steps to learning English and C, then discusses algorithms, flowcharts, tokens, data types, operators, control structures like if/else, switch, loops (while, do-while, for). It also covers nested loops, and illustrates an infinite loop that repeats until the user enters 'n'. The key topics covered include basic syntax, flow control, and programming constructs in C.
2. ‘C’ language is simple as compare to the English language
Here is steps comparison…
Steps in learning English language
Steps in learning ‘c’
alphabets words sentences paragraph
Alphabets , digits
Special symbols
Constants,
variables
keywords
instructi
ons
program
3. Before planning a program we need to define its logic
(the correct sequence of instructions need to solve the
problem at hand).the term algorithm is often used to
refer to the logic of a program.
It is a step by step description of how to arrive at the
solution of the given problem.(exp..)
*Write a program to find the larger of two given numbers.
Algorithm.
1.Input two numbers a and b
2.Assign big=a
3. If (b>big)the big=b
4.Output big
5.stop
4. Flowchart is the diagrammatic representation of
programs and algorithm . it is generally used to
understand the program and to solve the program
It uses boxes of different shapes to denote different
types of instructions.
The process of drawing a flowchart for an algorithm is
often referred to flowcharting
5. Only a few symbols are needed to indicate the necessary
operations in a flowchart. These basic flowchart symbols
have been standardized by the American National
standards institute (ANSI).
As shown……
flow lines
connector
start processing Input/output
decision
10. PRIMARY CONSTANT
Integer constant
Real constant
Character constant
Array
Pointer
Structure
Union
Enum.etc
SECONDARY CONSTANT
11. As we saw earlier , an entity that may vary during program
execution is called a variable.
Type of variable used in program depend on the type of
constant stored in it.
Float/real, integer ,or character constant
Variable name are name given to locations in memory
Exp….
float=6.0 (4 byte)
Int =6 (2 byte)
char=‘a’ (1 byte)
12. Keywords are the words whose meaning has already been
explained to the c compiler
The keywords cannot be used as variable name if we do so,
we are typing to assign new value to keywords which is not
allowed by compiler
There are 32 keywords available in c
Some are …….
short return double switch register signed
long void float union static unsigned
int break if goto continue volatile
char default for do sizeof enum
else case while auto extern typedef ..etc
13. • structure
•class
• integer
• float
•Character (char)
•int %d
•float %f
•char %c
•Array
•Pointer
•Function
•String
DATA TYPES
User define data type Fundamental data type Derived data type
16. && Means logical AND
|| Means logical OR
! Means logical NOT
LOGICAL OPERATOR
17. RELATIONAL OPERATORS
> Means greater than
< Means less than
== Means equal to
>= Means greater than equal to
<= Means less than equal to
!= Means not equals to
18.
19.
20.
21.
22. The general form of if statement is
if ( condition)
{
Statement-block
}
If condition is true the statement block will executed
otherwise the statement block will skipped.
27. The switch statement test the value of given expression
against a list of case values
General form
switch(expression)
{
case val-1:
statement-1
break;
case val-2:
statement-2;
break;
default:
default-statement;
break;
29. There are two types of repetitive structures
1. Conditional controlled (in this body is repetitively
executed until the given condition become true)
a) while statement
b) do while statement
2. Counter controlled (in this the number of time the set of
statement is executed ex.. )For loop
a) while statement
while(condition)
{
Statement(s);
}
30. 1. evaluate the condition.
2. If the condition true then execute the statement(s)and repeat step 1.
3. If the condition is false then the control is transferred out of loop.
Exp…..
#include<stdio.h>
main()
{
int num=1,s=0;
While(num<=10)
{
sum +=num;
num+1=1;
}
printf(“sum of first 10 natural numbers : %d ”, s);
getch();
}
RUN
Sum of first 10 natural num is : 55
The sequence of operation in while loop
32. In while statement, condition is evaluated first. Therefore
the body of loop may not be executed at all if condition
is not satisfied at the very first attempt. But in do loop,
condition is evaluated at the end. Therefore the body of
the loop is executed at lest once in this statement
The general form of this statement is..
do
{
Statement(s);
}
while (condition);
printf(“…………….”);
}
Do while statement
33. #include<stdio.>
main( )
{
int num=1,s=0;
do
{
s +=num;
num +=1;
}
while(num<=10);
printf(“sum of first natural no is %d”,s) ;
getch();
}
Run:
Sum of 10 natural number is 55.
(do while )..exp..sum of first 10 natural number
34. • The difference b/w. while & do while loop
I. In while the condition is tested before executing
body of loop. /In do while the condition is tested
after executing the body
II. Body of do loop is executed at lest once but body of
while loop may not be executed at all. /In while , If
initial the condition is not satisfied the loop will
to get executed even once
35. There are situation where you want to have a
statement or group of statements to be executed
numbers of time and the number of repetition does
not depend on the condition but it is simply a
repetition up to a certain numbers. The best way of
repetition is a for loop. The general form of the loop
for single statement is:
for ( initialization ; condition ; increment)
{
statement(s);
}
36. #include<stdio.h>
main( )
{
int I,s=0;
for (i=1;1<=10;i++)
s=s+1;
printf(“sum of first natural number is:%d”,s);
getch( );
}
Run:
Sum of first 10 natural number is : 55
37. Loop construct can be nested or embedded within one
another. The inner loop must be completely embedded
with the outer loop . There should no overlapping of loops.
**Demonstration of nested loops**
#include<stdio.h>
void main()
{
int r,c,sum;
for (r=1;r<=3;r++) /*outer loop*/
{
for(c=1;c<=2;c++) /*inner loop*/
{
sum=r+c;
printf(“r=%d c=%d sum=%dn”,r,c,sum);
}}
getch();
}
Output
r=1 c=1 sum=2
r=1 c=2 sum=3
r=2 c=1 sum=3
r=2 c=2 sum=4
38. The loop that we have used so far executed the statements within them a finite number of
times. However, in real life programming, one comes across a situation when it is not
known beforehand how many times the statements in the loop are to be executed. This
situation can be programmed as shown below:
/* execution of a loop an unknown number of times*/
#include<stdio.h>
void main()
{
Char another;
Int num;
do
{
printf(“enter a number”);
scanf(“%d”,&num);
printf(“square of%d is %d”, num, num*num);
Printf(“n want to enter another number y/n”);
Scanf(“%c”,&another);
}while(another==‘y’);
}
getch();
}
Output
Enter a number 5
Square of 5 is 25
Want to enter another number y/n y
Enter a number 7
Square of 7 is 49
Want to enter anotehr number y/n n