C Programming Lecture #3
C Programming Lecture #3
Control flow ka kaam hota hai ek program ko batana ki kaunsa kaam kab aur kaise karna hai.
If-Else, Ternary Operator, aur For Loop humare powerful tools hain to guide this flow.
Ab yeh mat sochna ki yeh sirf theory hai—iska asli mazza tab aayega jab tum inko use karke
🚀
questions solve karoge!
Let’s dive in!
1. If-Else Statement
If-Else ek decision-making tool hai. Agar koi condition true ho, toh kuch kaam karo, warna kuch
aur. Jese …..
if (condition) {
// Code when condition is true
} else {
// Code when condition is false
}
Example:
#include <stdio.h>
int main() {
int temp;
if (temp<=15) {
printf("Hello Friends Chai Pi Lo! \n");
} else {
printf("Juice Pilado Mosambi Ka ! \n");
}
return 0;
}
2. Ternary Operator
Ternary operator ek compact version hai if-else ka. Iska use simple ya kahu one liner decisions
ke liye hota hai.
Syntax:
condition ? value_if_true : value_if_false;
Example:
#include <stdio.h>
int main() {
int number;
return 0;
}
3. For Loop
Ab tumhe repetitive kaam karna hai,jese apne dost ko 200 birthday messages bhejne hai, toh
kya manually likhoge? Bilkul nahi!
For loop tumhare repetitive tasks ko automate karta hai.
Syntax:
for (initialization; condition; increment/decrement) {
// Code to execute repeatedly
}
For Loop Examples:
#include <stdio.h>
int main() {
int A, B;
return 0;
}
#include <stdio.h>
int main() {
int A, B, sum = 0;
int main() {
int A, B;
return 0;
}
int main() {
int A, B, sum = 0;
int main() {
int n, fact = 1;
int main() {
int n;
return 0;
}
int main() {
int n, sum = 0;
int main() {
int n, count = 0;
int main() {
int n, isPrime = 1;
if (n < 2) isPrime = 0;
if (isPrime) {
printf("%d is a prime number.\n", n);
} else {
printf("%d is not a prime number.\n", n);
}
return 0;
}
After seeing so many codes
int main() {
int A, B;
return 0;
}
Questions for Practice
If-Else Questions:
1. Write a program to check if a number is odd or even using the ternary operator.
Super Challenge:
Create a program that calculates the sum of all prime numbers between two numbers A and B.
🔥
Thike boss, aaj ke liye itna kaafi hai! Angaari banne ke liye practice karo aur homework time par
submit karna mat bhoolna!
Here is a link to understand if else better:-
https://www.youtube.com/watch?v=gzmEcP2MmIM&list=PLtlkmeoc1tYHFCOvN7ECrpOY3-k6pI
EN_&index=8
https://www.youtube.com/watch?v=pwsIE3Qnr9g&list=PLtlkmeoc1tYFS2F8gEPuEts2Vuyrgu7l4