0% found this document useful (0 votes)
38 views3 pages

Essential C Language Practical Programs

The document outlines important C language practical programs covering basic input/output operations, conditional statements, loops, arrays, strings, functions, pointers, structures, and file handling. It includes example codes for arithmetic operations, swapping numbers, calculating interest, temperature conversion, and various algorithms. Additionally, it provides insights into data structures and file operations 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)
38 views3 pages

Essential C Language Practical Programs

The document outlines important C language practical programs covering basic input/output operations, conditional statements, loops, arrays, strings, functions, pointers, structures, and file handling. It includes example codes for arithmetic operations, swapping numbers, calculating interest, temperature conversion, and various algorithms. Additionally, it provides insights into data structures and file operations 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

C LANGUAGE PRACTICAL – IMPORTANT PROGRAMS

1. BASIC INPUT/OUTPUT

- Add, subtract, multiply, divide two numbers

Logic: Take two numbers, apply arithmetic operators.

Code:

#include

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

printf("%d %d %d %d",a+b,a-b,a*b,a/b);}

- Swap two numbers (with temp)

Logic: Use third variable.

Code:

int a,b,t; t=a; a=b; b=t;

- Swap without temp

a=a+b; b=a-b; a=a-b;

- Simple/Compound Interest

SI = (P*R*T)/100; CI = P*(pow((1+R/100),T))-P;

- Temperature Convert

C→F: F = (C*9/5)+32; F→C: C = (F-32)*5/9;

2. CONDITIONAL STATEMENTS

- Even/Odd: if(n%2==0)

- Greatest of 3: if(a>b && a>c)

- Vowel check: if(ch=='a'||ch=='e'...)

- Positive/Negative/Zero: if(n>0) else if(n<0)

- Prime: iterate i=2 to n/2

- Leap year: if((y%400==0)||(y%4==0 && y%100!=0))

3. LOOPS

- Factorial: loop multiply 1..n

- Fibonacci: print a=0,b=1,... next=a+b

- Multiplication table: loop from 1–10


- Sum 1..n: loop sum+=i

- Reverse number: rev=rev*10+n%10

- Palindrome: if(reverse==original)

4. ARRAYS

- Largest/smallest: iterate compare

- Sort: bubble sort

- Sum: loop add

- Linear search: loop check element

- Binary search: mid compare

5. STRINGS

- Length: loop till '■'

- Reverse: swap front/back

- Palindrome: compare reverse

- Compare: loop match chars

- Concatenate: append at '■'

6. FUNCTIONS

- Factorial: recursion

- GCD: Euclid algorithm

- Prime: check divisor

- Call by value/reference difference

7. POINTERS

- Pointer basics: int *p=&a;

- Swap using pointers

- Pointer to array: p=&arr;[0]

8. STRUCTURES

- Input/print student data

struct student{char name[20]; int age; float marks;};

9. FILE HANDLING

- fopen(), fclose(), fputs(), fgets()


- r, w, a, rb, wb modes

You might also like