0% found this document useful (0 votes)
25 views4 pages

Chapter 3 Code

chap 3 codes bca c language

Uploaded by

shaikhhasan0036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Chapter 3 Code

chap 3 codes bca c language

Uploaded by

shaikhhasan0036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C Language Tutorial

(Basic to Advanced)

Topics to be covered :
Installation + Setup
Chapter 1 - Variables, Data types + Input/Output
Chapter 2 - Instructions & Operators
Chapter 3 - Conditional Statements
Chapter 4 - Loop Control Statements
Chapter 5 - Functions & Recursion
Chapter 6 - Pointers
Chapter 7 - Arrays
Chapter 8 - Strings
Chapter 9 - Structures
Chapter 10 - File I/O
Chapter 11 - Dynamic Memory Allocation

Conditional Statements
(Chapter 3)

1. If-else
#include<stdio.h>

int main() {
int age = 19;
if(age >= 18) {
printf("you are an adult");
}
else {
printf("you are not an adult");
}
return 0;
}

> check if a number is odd or even


#include<stdio.h>

int main() {
int number;
scanf("%d", &number);

if(number % 2 == 0) {
printf("even");
}
else {
printf("odd");
}
return 0;
}

> Use of else if


#include<stdio.h>

int main() {
int age;
printf("Enter age : ");
scanf("%d", &age);

if(age < 12) {


printf("child");
}
else if(age < 18) {
printf("teenager");
}
else {
printf("adult");
}
return 0;
}

2. Ternary Operator
#include<stdio.h>

int main() {
int age;
printf("Enter age : ");
scanf("%d", &age);

age > 18 ? printf("adult \n") : printf("not adult \n");

int number = 7;
int luckyNumber = 7;

number == luckyNumber ? printf("you are lucky \n") : printf("you are not


lucky \n");

return 0;
}

3. Switch (integer)
#include<stdio.h>
#include<math.h>

int main() {
int day = 5;
switch(day) {
case 1 : printf("monday \n");
break;
case 2 : printf("tuesday \n");
break;
case 3 : printf("wednesday \n");
break;
case 4 : printf("thursday \n");
break;
case 5 : printf("friday \n");
break;
case 6 : printf("saturday \n");
break;
case 7 : printf("sunday \n");
break;
}
return 0;
}

4. Switch (character)
#include<stdio.h>
#include<math.h>

int main() {
char day = 'f';
switch(day) {
case 'm' : printf("monday \n");
break;
case 't' : printf("tuesday \n");
break;
case 'w' : printf("wednesday \n");
break;
case 'T' : printf("thursday \n");
break;
case 'f' : printf("friday \n");
break;
case 's' : printf("saturday \n");
break;
case 'S' : printf("sunday \n");
break;
}
return 0;
}

You might also like