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

Key C Program Logic for BCA Practicals

The document outlines the logic for various important C programming tasks typically covered in BCA 1st semester practicals. It includes operations such as arithmetic calculations, number manipulation, string handling, and file operations, providing concise logic for each task. The document serves as a guide for understanding fundamental programming concepts and techniques in C.

Uploaded by

naturebylens0
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)
2 views4 pages

Key C Program Logic for BCA Practicals

The document outlines the logic for various important C programming tasks typically covered in BCA 1st semester practicals. It includes operations such as arithmetic calculations, number manipulation, string handling, and file operations, providing concise logic for each task. The document serves as a guide for understanding fundamental programming concepts and techniques in C.

Uploaded by

naturebylens0
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

LOGIC OF ALL IMPORTANT C PROGRAMS (BCA 1ST SEM – PRACTICALS)

1. Add, Subtract, Multiply, Divide Two Numbers

Logic: Take two numbers from user → apply +, -, *, / operators → print results.

2. Swap Two Numbers (Using Third Variable)

Logic: Use a temporary variable to hold one number → swap values.

3. Swap Without Third Variable

Logic: Use arithmetic: a = a+b; b = a-b; a = a-b.

4. Simple Interest

Logic: SI = (P * R * T) / 100.

5. Temperature Conversion

Logic: Celsius to Fahrenheit → F = (C * 9/5) + 32.

6. Even or Odd

Logic: A number is even if num % 2 == 0 else odd.

7. Greatest of Three Numbers

Logic: Compare using nested if/else or logical operators.

8. Vowel or Consonant

Logic: Check if character matches a, e, i, o, u (both cases).

9. Positive, Negative, Zero

Logic: If num > 0 → positive; < 0 → negative; else zero.

10. Prime Number

Logic: A number is prime if divisible by 1 and itself → check divisibility from 2 to n/2.

11. Leap Year


Logic: Year divisible by 4 → leap except century years unless divisible by 400.

12. Factorial

Logic: Multiply numbers from 1 to n using loop.

13. Fibonacci Series

Logic: Start with 0, 1 → next term = sum of previous two.

14. Multiplication Table

Logic: Loop from 1 to 10 → multiply each step by number.

15. Reverse a Number

Logic: Extract digits using %10 → build reverse using reverse*10 + digit.

16. Palindrome Number

Logic: Reverse number → check if original == reversed.

17. Largest Element in Array

Logic: Assume arr[0] is largest → compare with each element.

18. Smallest Element in Array

Logic: Same as largest, but check smaller values.

19. Sort Array

Logic: Use bubble sort or simple nested loops to swap values.

20. Sum of Array Elements

Logic: Loop through array → accumulate sum.

21. Linear Search

Logic: Compare key with each element one-by-one.

22. Binary Search

Logic: Use mid index → compare and eliminate half array each step (sorted array required).
23. String Length (Without Library)

Logic: Use loop → count characters until '\0'.

24. Reverse String

Logic: Swap characters from start and end moving inward.

25. Palindrome String

Logic: Compare string with its reversed version.

26. Compare Two Strings

Logic: Check characters one-by-one until difference is found.

27. Concatenate Strings

Logic: Move to end of first string → start copying second string.

28. Function – Factorial

Logic: Use recursion or loop inside function.

29. Function – GCD

Logic: Use Euclidean algorithm: gcd(a, b) = gcd(b, a % b).

30. Prime using Function

Logic: Create function to check divisibility inside loop.

31. Call by Value vs Reference

Logic: Value passes copy; reference passes address → actual variable changes only by reference.

32. Pointer Basics

Logic: Pointer stores memory address → *pointer gives value at that address.

33. Swap Using Pointers

Logic: Dereference pointers to access & swap values.


34. Pointer to Array

Logic: Pointer holds address of first element → *(p+i) accesses array elements.

35. Structures – Student Record

Logic: Define structure → use dot operator to assign & display values.

36. Structure vs Union

Logic: Structure stores all members separately; union shares same memory → only one active at a
time.

37. File Write

Logic: Open file in "w" mode → fprintf/fputs to write.

38. File Read

Logic: Open file in "r" mode → fgets/fscanf to read.

39. EOF Logic

Logic: Loop continues until End of File is reached.

You might also like