C Language 20 Basic Program Notes
C Language 20 Basic Program Notes
REALtechSmart
1. Hello World
2. Sum of Two Numbers
3. Find Even or Odd
4. Check Prime Number
5. Factorial of a Number
6. Fibonacci Series
7. Reverse a Number
8. Palindrome Number
9. Armstrong Number
10. Swap Two Numbers
11. Find Largest of Three Numbers
12. Simple Calculator (Switch Case)
13. Count Digits in a Number
14. Sum of Digits
15. Multiplication Table
16. Check Leap Year
17. Print Alphabets A–Z
18. ASCII Value of a Character
19. Convert Temperature (C to F)
20. GCD of Two Numbers
Would you like me to generate and send this Word file now?
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
2|Page
REALtechSmart
1. Hello World
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
#include <stdio.h>
int main()
int a, b, sum;
sum = a + b;
return 0;
#include <stdio.h>
int main()
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
3|Page
REALtechSmart
int num;
scanf("%d", &num);
if(num % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
#include <stdio.h>
int main()
scanf("%d", &num);
if(num % i == 0) {
flag = 1;
break;
if(num == 1)
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
4|Page
REALtechSmart
else if(flag == 0)
else
return 0;
5. Factorial of a Number
#include <stdio.h>
int main()
int n, i;
scanf("%d", &n);
fact *= i;
return 0;
6. Fibonacci Series
#include <stdio.h>
int main()
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
5|Page
REALtechSmart
{
int i, n, t1 = 0, t2 = 1, nextTerm;
scanf("%d", &n);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
return 0;
7. Reverse a Number
#include <stdio.h>
int main()
scanf("%d", &num);
while(num != 0) {
num /= 10;
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
6|Page
REALtechSmart
return 0;
8. Palindrome Number
#include <stdio.h>
int main()
scanf("%d", &n);
original = n;
while(n != 0) {
remainder = n % 10;
n /= 10;
if(original == reversed)
printf("Palindrome");
else
printf("Not a palindrome");
return 0;
9. Armstrong Number
#include <stdio.h>
int main()
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
7|Page
REALtechSmart
{
scanf("%d", &num);
originalNum = num;
while(originalNum != 0) {
originalNum /= 10;
if(result == num)
printf("Armstrong number");
else
return 0;
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d", a, b);
return 0;
}
#include <stdio.h>
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
8|Page
REALtechSmart
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a >= b && a >= c)
printf("%d is the largest.", a);
else if(b >= a && b >= c)
printf("%d is the largest.", b);
else
printf("%d is the largest.", c);
return 0;
}
#include <stdio.h>
int main() {
char op;
double num1, num2;
printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &num1, &num2);
switch(op) {
case '+': printf("%.1lf + %.1lf = %.1lf", num1, num2, num1 + num2);
break;
case '-': printf("%.1lf - %.1lf = %.1lf", num1, num2, num1 - num2);
break;
case '*': printf("%.1lf * %.1lf = %.1lf", num1, num2, num1 * num2);
break;
case '/':
if(num2 != 0)
printf("%.1lf / %.1lf = %.1lf", num1, num2, num1 / num2);
else
printf("Division by zero error.");
break;
default: printf("Invalid operator");
}
return 0;
}
#include <stdio.h>
int main() {
int num, count = 0;
printf("Enter a number: ");
scanf("%d", &num);
while(num != 0) {
num /= 10;
count++;
}
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
9|Page
REALtechSmart
printf("Number of digits: %d", count);
return 0;
}
#include <stdio.h>
int main() {
int num, sum = 0;
printf("Enter a number: ");
scanf("%d", &num);
while(num != 0) {
sum += num % 10;
num /= 10;
}
printf("Sum of digits = %d", sum);
return 0;
}
#include <stdio.h>
int main() {
int n, i;
printf("Enter a number: ");
scanf("%d", &n);
for(i = 1; i <= 10; ++i) {
printf("%d x %d = %d\n", n, i, n*i);
}
return 0;
}
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
return 0;
}
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
10 | P a g e
REALtechSmart
#include <stdio.h>
int main() {
char ch;
for(ch = 'A'; ch <= 'Z'; ch++) {
printf("%c ", ch);
}
return 0;
}
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII value of %c = %d", c, c);
return 0;
}
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("Temperature in Fahrenheit: %.2f", fahrenheit);
return 0;
}
#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
while(a != b) {
if(a > b)
a -= b;
else
b
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
11 | P a g e
REALtechSmart
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY