Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Course instructor :
Prof. Kumar Anand Singh
(Asst. Professor, EC, MEFGI)
Course assistances:
Prof. Hetal Dave
(Asst. Professor, EC, MEFGI)
Mr. Saumil Vora
(Student, PG-VLSI, 1st year)
Topic
Date
Total Hours
TH (hrs.)
PR(hrs.)
1.
Introduction
0.5
1.
Basic Structure
0.5
2.
C Fundamentals
3.
I/O Functions
4.
Control statements
5.
Arrays
6.
7.
Functions
8.
9.
Pointers
10.
11.
File handling
12.
13.
Introduction to Embedded C
40
20
Control Statements
Decision Control
If statements
If else statements
Nested if statements
Case Control
Loop Control
for
while
do-while
switch
break
continue
goto
Decision Control
Group of statements are executed when condition is true. If condition is
false, then else part statements are executed.
if statement :
Syntax :
if (condition)
{ Statements; }
int main()
{
int m=40,n=40;
if (m == n)
{
printf("m & n are equal");
}
output :
m & n are equal
ifelse statement :
Syntax :
if (condition)
{ Statement1; Statement2; }
else
{ Statement3; Statement4; }
int main()
{
int m=40,n=20;
if (m == n)
{
printf("m and n are equal");
}
else
{
printf("m & n r not equal");
}
}
nested if statement
Syntax :
if(condition1)
{
Statement1;
}
else_
if(condition2)
{
Statement2;
}
else
Statement 3;
Loop Control
for loop
for (exp1; exp2; expr3)
{
statements;
}
while loop
while (condition)
{
statements;
}
Where,
exp1 variable initialization
( Example: i=0, j=2, k=3 )
Where,
condition might be a>5,
i<10
do while loop
do
{
statements;
}while (condition);
for Loop :
while Loop :
output :
3456789
do while Loop :
#include <stdio.h>
int main()
{
int i=1;
do
{
printf("Value of i is %d\n",i);
i++;
}while(i<=4 && i>=2);
}
output :
Value of
Value of
Value of
Value of
i
i
i
i
is
is
is
is
1
2
3
4
Case Control
int main ()
{
int value = 3;
switch(value)
{
case 1:
printf(Value is 1 \n );
break;
case 2:
printf(Value is 2 \n );
break;
case 3:
printf(Value is 3 \n );
break;
case 4:
printf(Value is 4 \n );
break;
default :
printf(Value is other than 1,2,3,4 \n );
}
return 0;
}
output: Value is 3
Case Control
2. break statement
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5)
{
printf(\nComing out of for loop when i = 5);
break;
}
printf(%d ,i);
}
}
Output:
01234
Coming out of for loop when i = 5
Case Control
3. Continue statement
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5 || i==6)
{
printf(\nSkipping %d from display using \continue statement \n,i);
continue;
}
printf(%d ,i);
}
}
Output:
01234
Skipping 5 from display using continue statement
Skipping 6 from display using continue statement
789
Case Control
4. goto statement
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5)
{
printf(\nWe are using goto statement when i = 5);
goto HAI;
}
printf(%d ,i);
}
HAI : printf(\nNow, we are inside label name \hai\ \n);
}
Output:
01234
We are using goto statement when i = 5
Now, we are inside label name hai
for(i=0;i<10;i++)
{
for(j=0;j<i;j++)
printf(Hello);
}
for(i=10;i>0;i--)
{
for(j=0;j<10;j++)
printf(Hello);
}
for(i=10;i>0;i--)
{
for(j=0;j<i;j++)
printf(Hello);
}
for(i=5;i>0;i--)
{
for(j=0;j<i;j++)
printf(*);
printf(\n);
}
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
printf(*);
printf(\n);
}
i=0;
for(;i<5;)
{
for(j=0;j<i;j++)
printf(%d,i);
i++;
}
for(i=5;i>0;i--)
{
for(j=0;j<i;j++)
printf(*\n);
i=0;
for(;i<5;)
{
for(j=0;j<i;j++)
printf(%d,j);
i++;
}
*
**
***
****
*****
******
Problems ??????