Professional Documents
Culture Documents
Statements;
if(condi False
if(condition) tion)
{
True
True block statements;
} True Block False Block
Statement Statements
else
{
False block statements;
}
False Statements2;
Default Statements;
Statements3;
Case 1 Statements
Case 2 Statements
Case 3 Statements
Case 4 Statements
do-while statement
for statement
False
Prepared by Kiruthika S.S., AP/ CSE/ SRMIST, Ramapuram 26
do..while statement example
//Sum of n numbers Output:
#include<stdio.h> Enter a number: 5
void main() Sum of 5 numbers is 15
{
int n,x=1,sum=0;
printf("Enter a number: ");
scanf("%d",&n);
do
{
sum=sum+x;
x++;
} while(x<=n);
printf("Sum of %d numbers is %d",n, sum);
}
Prepared by Kiruthika S.S., AP/ CSE/ SRMIST, Ramapuram 27
do..while statement example
//Find the reverse of a given number Output
#include<stdio.h> Enter the number:275
void main() Reversed number is 572
{
int n, rem, reverse=0;
printf(“Enter the number:”);
scanf(“%d”,&n);
do
{
rem=n%10;
reverse=reverse*10+rem;
n=n/10;
} while(n>0);
printf(“\nReversed number is %d”,reverse);
}
Increment/Decrement;
True test
condition
False
}
printf(“Sum of series=%d”,sum);
}
1) Syntax: 1) Syntax:
break; continue;
2) Takes the control to outside of 2) Takes the control to beginning of
the loop the loop
3) It is used in switch statement, 3) It is used in for statement, while
for statement, while and do..while and do..while statement but not in
statement switch statement
4) Example: 4) Example:
for(i=0;i<n;i++) for(i=0;i<n;i++)
{ {
if(i==3) if(i<=3)
break; continue;
} }
Prepared by Kiruthika S.S., AP/ CSE/ SRMIST, Ramapuram 43
Array
Array is a collection of similar data items, which are stored
under a common name
A value in array is identified by index or subscript enclosed
in square brackets with array number
Eg: a[n]
a – Name of the array
n – no of elements in the array
The array value starts from the index 0 (ie) a[0]
Array elements are stored in contiguous memory location
Arrays can be classified into 2 types
1-dimensional array
2-dimensional array
Multi-dimensional array
Prepared by Kiruthika S.S., AP/ CSE/ SRMIST, Ramapuram 44
Characteristics of Array
Instead of declaring n variables for n values, only one
variable is enough using array
Ex: int a[3];
All the elements of an array share the same name
Element number in an array plays major role for
accessing each element
Ex: int a[3]={1,2,3};
a[0]=1
a[1]=2
a[2]=3
Features of Pointer
Pointers save memory space
Execution time of using pointer is faster
Pointers are used with data structure
Pointers are used in file handling
Examples
int *iptr; //iptr is a pointer to an integer variable
float *fptr; //fptr is a pointer to a floating point variable
char *cptr; //cptr is a pointer to a character
const int *ptric; //ptric is a pointer to an integer constant
a = 10 1003
1008