0% found this document useful (0 votes)
4 views11 pages

C Language 20 Basic Program Notes

The document contains a list of 20 programming tasks, primarily in C language, including basic operations like 'Hello World', calculating the sum of two numbers, and checking for prime numbers. Each task is accompanied by its corresponding code snippet. The document appears to be aimed at beginners learning programming concepts and syntax.

Uploaded by

myindiabharat600
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)
4 views11 pages

C Language 20 Basic Program Notes

The document contains a list of 20 programming tasks, primarily in C language, including basic operations like 'Hello World', calculating the sum of two numbers, and checking for prime numbers. Each task is accompanied by its corresponding code snippet. The document appears to be aimed at beginners learning programming concepts and syntax.

Uploaded by

myindiabharat600
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/ 11

1|Page

REALtechSmart

Here’s what the list will include:

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;

2. Sum of Two Numbers

#include <stdio.h>

int main()

int a, b, sum;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

sum = a + b;

printf("Sum: %d", sum);

return 0;

3. Find Even or Odd

#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;

printf("Enter a number: ");

scanf("%d", &num);

if(num % 2 == 0)

printf("Even");

else

printf("Odd");

return 0;

4. Check Prime Number

#include <stdio.h>

int main()

int num, i, flag = 0;

printf("Enter a number: ");

scanf("%d", &num);

for(i = 2; i <= num / 2; ++i) {

if(num % i == 0) {

flag = 1;

break;

if(num == 1)

printf("1 is neither prime nor composite.");

REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
4|Page
REALtechSmart
else if(flag == 0)

printf("%d is a prime number.", num);

else

printf("%d is not a prime number.", num);

return 0;

5. Factorial of a Number

#include <stdio.h>

int main()

int n, i;

unsigned long long fact = 1;

printf("Enter a number: ");

scanf("%d", &n);

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

fact *= i;

printf("Factorial = %llu", fact);

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;

printf("Enter the number of terms: ");

scanf("%d", &n);

for(i = 1; i <= n; ++i) {

printf("%d ", t1);

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

return 0;

7. Reverse a Number

#include <stdio.h>

int main()

int num, reversed = 0, remainder;

printf("Enter an integer: ");

scanf("%d", &num);

while(num != 0) {

remainder = num % 10;

reversed = reversed * 10 + remainder;

num /= 10;

printf("Reversed number = %d", reversed);

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()

int n, reversed = 0, remainder, original;

printf("Enter an integer: ");

scanf("%d", &n);

original = n;

while(n != 0) {

remainder = n % 10;

reversed = reversed * 10 + remainder;

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
{

int num, originalNum, remainder, result = 0;

printf("Enter a three-digit number: ");

scanf("%d", &num);

originalNum = num;

while(originalNum != 0) {

remainder = originalNum % 10;

result += remainder * remainder * remainder;

originalNum /= 10;

if(result == num)

printf("Armstrong number");

else

printf("Not an Armstrong number");

return 0;

10. Swap Two Numbers

#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;
}

11. Largest of Three Numbers

#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;
}

12. Simple Calculator (Switch Case)

#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;
}

13. Count Digits

#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;
}

14. Sum of Digits

#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;
}

15. Multiplication Table

#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;
}

16. Leap Year Check

#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

17. Print Alphabets A-Z

#include <stdio.h>
int main() {
char ch;
for(ch = 'A'; ch <= 'Z'; ch++) {
printf("%c ", ch);
}
return 0;
}

18. ASCII Value of Character

#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII value of %c = %d", c, c);
return 0;
}

19. Convert Celsius to Fahrenheit

#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;
}

20. GCD of Two Numbers

#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

You might also like