25

C programming flow of controls

Embed Size (px)

DESCRIPTION

C programming flow of controls

Citation preview

Page 1: C  programming flow of controls
Page 2: C  programming flow of controls

EXTRA

Page 3: C  programming flow of controls

NOTES

Page 4: C  programming flow of controls

NOTES

Page 5: C  programming flow of controls

#include<stdio.h>

#include<conio.h>

void main()

{

int age;

clrscr();

printf(“Enter age\n”);

scanf(“%d”, &age);

if(age>=18)

{

printf(“Eligible for Vote”);

}

else

{

printf(“Not Eligible for Vote”);

}

getch();

}

EXTRA

Page 6: C  programming flow of controls

EXTRA

Page 7: C  programming flow of controls

NOTES

Page 8: C  programming flow of controls

#include<stdio.h>

#include<conio.h>

void main()

{

int age;

clrscr();

printf(“Enter age\n”);

scanf(“%d”, &age);

if(age>=18)

{

if(age>=25)

{

printf(“Eligible for Vote & Marriage ”);

}

else

{

printf(“Eligible for Vote but not Marriage ”);

}

}

else

{

printf(“Not Eligible for Vote & Marriage”);

}

getch();

}

EXTRA

Page 9: C  programming flow of controls

EXTRA

Page 10: C  programming flow of controls

NOTES

Page 11: C  programming flow of controls

#include<stdio.h>#include<conio.h>void main(){

int roll;clrscr();printf(“Enter Roll No\n”);scanf(“%d”, &roll);switch(roll){

case 1: printf(“Raj”);break;case 2: printf(“Anita”);break;case 3: printf(“Babita”);break;

default: printf(“Invalid Roll No”);}getch();

}

EXTRA

Page 12: C  programming flow of controls

if condition & Go to statement

#include<stdio.h>#include<conio.h>void main(){

int a=1;clrscr();start:printf(“%d\n”,a++);if(a<=10)goto start;getch();

}

EXTRA

Page 13: C  programming flow of controls

NOTES

Page 14: C  programming flow of controls

NOTES

Page 15: C  programming flow of controls

EXTRA

Page 16: C  programming flow of controls

NOTES

Page 17: C  programming flow of controls

#include<stdio.h>

#include<conio.h>

void main()

{

int i;

clrscr();

for(i=1;i<=10;i++)

{

printf(“%d\n”,i);

}

getch();

}

EXTRA

Page 18: C  programming flow of controls

EXTRA

Page 19: C  programming flow of controls

NOTES

Page 20: C  programming flow of controls

#include<stdio.h>#include<conio.h>void main(){

int i=1,n=2;clrscr();while(i<=10){

printf(“%d\n”, n*i);i++;

}getch();

}

EXTRA

Page 21: C  programming flow of controls

NOTES

Page 22: C  programming flow of controls

#include<stdio.h>#include<conio.h>void main(){

int a=0,b=1,c=0,n=3;clrscr();printf(“%d ”,a);printf(“%d ”,b);do{

c=a+b;printf(“%d ”,c);a=b;b=c;n++;

}while(n<=10);getch();

}

EXTRA

Page 23: C  programming flow of controls

NOTES

Page 24: C  programming flow of controls

NOTES

Page 25: C  programming flow of controls

#include<stdio.h>#include<conio.h>void main(){

int i;clrscr();printf(“the loop with break produces output as \n”);for(i=1;i<=10;i++){

if(i%3==0){

break;}else{

printf(“%d\n”,i);}

}prinf(“The loop with continue produces output as\n”);for(i=1;i<=10;i++){

if(i%3==0){

continue;}else{

printf(“%d\n”,i);}

}getch();

}

EXTRA