BCSE102L Structured and Object Oriented: Programming
BCSE102L Structured and Object Oriented: Programming
Structured
and
Object By,
Dr. S. Vinila Jinny,
Oriented ASP/SCOPE
Programming
C is mother language of all programming
language.
It is a popular computer programming
language.
It is procedure-oriented programming
language.
It is also called mid level programming
language.
C programming language was developed in
1972 by Dennis Ritchie at bell laboratories
of AT&T(American Telephone & Telegraph),
located in U.S.A.
Dennis Ritchie is known as founder of c
language.
It was developed to be used in UNIX
Operating system.
It inherits many features of previous
languages such as B and BPCL.
Language year Developed By
ALGOL 1960 International Group
BPCL 1967 Martin Richards
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K&RC 1978 Kernighan & Dennis
Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization
Committee
There are many features of c language are given below.
}
Loops are used to execute a block of code or
a part of program of the program several
times.
Types of loops in C language:-
There are 3 types of loops in c language.
1) do while
2) while
3) for
It is better if you have to execute the code
at least once.
Syntax:-
do{
//code to be executed
}while(condition);
#include<stdio.h>
int main(){
int i=1;
do{
printf("%d \n",i);
i++;
}while(i<=10);
return 0;
}
It is better if number of iteration is not
known by the user.
Syntax:-
while(condition){
//code to be executed
}
#include<stdio.h>
int main(){
int i=1;
while(i<=10){
printf("%d \n",i);
i++;
}
return 0;
}
It is good if number of iteration is known by
the user.
Syntax:-
for(initialization;condition;incr/decr){
//code to be executed
}
#include<stdio.h>
int main(){
int i=1,number=0;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=10;i++){
printf("%d \n",(number*i));
}
return 0;
}
it is used to break the execution of loop
(while, do while and for) and switch case.
Syntax:-
jump-statement;
break;
#include<stdio.h>
void main ()
{
int i = 0;
while(1)
{
printf("%d ",i);
i++;
if(i == 10)
break;
}
printf("came out of while loop");
}
it is used to continue the execution of loop
(while, do while and for). It is used with if
condition within the loop.
Syntax:-
jump-statement;
continue;
#include<stdio.h>
void main ()
{
int i = 0;
while(i!=10)
{
printf("%d", i);
continue;
i++;
}
}
The goto statement is a jump statement which is
sometimes also referred to as unconditional jump
statement. The goto statement can be used to jump
from anywhere to anywhere within a function.
Syntax1:
goto label;
------
-------
label:
Syntax2:
label:
------
-------
goto label;
#include <stdio.h>
// C program to check if a number is
void checkEvenOrNot(int num)
// even or not using goto statement
{
if (num % 2 == 0)
goto even; int main()
else
goto odd; {
int num = 26;
even:
printf("%d is even", num); checkEvenOrNot(num);
return; return 0;
odd:
printf("%d is odd", num); }
}