fa
Feedback
C Programming Codes

C Programming Codes

رفتن به کانال در Telegram

C Programming Codes || Quizzes || DSA Learn along with the community Any queries admin - @Pradeep_saii

نمایش بیشتر

📈 تحلیل کانال تلگرام C Programming Codes

کانال C Programming Codes (@c_programming_codes) در بخش زبانی انگلیسی بازیگری فعال است. در حال حاضر جامعه شامل 13 433 مشترک است و جایگاه 9 525 را در دسته فناوری و برنامه‌ها و رتبه 32 112 را در منطقه الهند دارد.

📊 شاخص‌های مخاطب و پویایی

از زمان ایجاد در невідомо، پروژه رشد سریعی داشته و 13 433 مشترک جذب کرده است.

بر اساس آخرین داده‌ها در تاریخ 10 ژوئن, 2026، کانال فعالیت پایداری دارد. در ۳۰ روز گذشته تغییر اعضا برابر -232 و در ۲۴ ساعت گذشته برابر -3 بوده و همچنان دسترسی گسترده‌ای حفظ شده است.

  • وضعیت تأیید: تأیید نشده
  • نرخ تعامل (ER): میانگین تعامل مخاطب 9.77% است و در ۲۴ ساعت نخست پس از انتشار، محتوا معمولاً N/A% واکنش نسبت به کل مشترکان کسب می‌کند.
  • دسترسی پست‌ها: هر پست به طور میانگین 0 بازدید دریافت می‌کند. در اولین روز معمولاً 0 بازدید جمع‌آوری می‌شود.
  • واکنش‌ها و تعامل: مخاطبان به‌طور فعال حمایت می‌کنند؛ میانگین واکنش به هر پست 0 است.
  • علایق موضوعی: محتوا بر موضوعات کلیدی مانند input, string, scanf("%d, array, element تمرکز دارد.

📝 توضیح و سیاست محتوایی

نویسنده این فضا را محل بیان دیدگاه‌های شخصی توصیف می‌کند:
C Programming Codes || Quizzes || DSA Learn along with the community Any queries admin - @Pradeep_saii

به لطف به‌روزرسانی‌های پرتکرار (آخرین داده در تاریخ 11 ژوئن, 2026)، کانال همواره به‌روز و دارای دسترسی بالاست. تحلیل‌ها نشان می‌دهد مخاطبان به‌طور فعال با محتوا تعامل دارند و آن را به نقطه اثرگذاری مهم در دسته فناوری و برنامه‌ها تبدیل کرده‌اند.

13 433
مشترکین
-324 ساعت
-477 روز
-23230 روز
آرشیو پست ها
💻 Check Prime Number Using Recursion
#include <stdio.h>
#include <stdbool.h>

bool isPrimeRecursive(int n, int i) {
    if (n <= 1)
        return false;
    if (i == 1)
        return true;
    if (n % i == 0)
        return false;
    return isPrimeRecursive(n, i - 1);
}

int main() {
    int num;
    printf("Enter a positive integer: ");
    scanf("%d", &num);

    if (isPrimeRecursive(num, num / 2))
        printf("%d is a prime number.n", num);
    else
        printf("%d is not a prime number.n", num);

    return 0;
}
📤 Output:
Input: 7
Output: 7 is a prime number.

Input: 12
Output: 12 is not a prime number.

Input: 1
Output: 1 is not a prime number.

💻 Product of Two Numbers Using Recursion
#include <stdio.h>

int product(int a, int b) {
    if (b == 0) {
        return 0;
    } else if (b > 0) {
        return a + product(a, b - 1);
    } else {
        return -product(a, -b);
    }
}

int main() {
    int num1, num2, result;

    printf("Enter two integers: ");
    scanf("%d %d", &num1, &num2);

    result = product(num1, num2);

    printf("Product of %d and %d is: %dn", num1, num2, result);

    return 0;
}
📤 Output:
Input: 5 3
Output: Product of 5 and 3 is: 15

Input: 4 -2
Output: Product of 4 and -2 is: -8

Input: -6 2
Output: Product of -6 and 2 is: -12

Input: -3 -4
Output: Product of -3 and -4 is: 12

Input: 7 0
Output: Product of 7 and 0 is: 0

💻 Sum of Natural Numbers Using Recursion
#include <stdio.h>

int sum(int n) {
  if (n == 0) {
    return 0;
  } else {
    return n + sum(n - 1);
  }
}

int main() {
  int num;

  printf("Enter a positive integer: ");
  scanf("%d", &num);

  if (num < 0) {
    printf("Please enter a positive integer.n");
  } else {
    int result = sum(num);
    printf("Sum = %dn", result);
  }

  return 0;
}
📤 Output:
Input: 10
Output: Enter a positive integer: Sum = 55

Input: 5
Output: Enter a positive integer: Sum = 15

Input: -3
Output: Enter a positive integer: Please enter a positive integer.

💻 Print Numbers from N to 1 Using Recursion
#include <stdio.h>

void printNumbers(int n) {
    if (n > 0) {
        printf("%d ", n);
        printNumbers(n - 1);
    }
}

int main() {
    int n;
    printf("Enter a positive integer: ");
    scanf("%d", &n);

    printNumbers(n);
    printf("n");

    return 0;
}
📤 Output:
Input: 5
Output: 5 4 3 2 1

💻 Print Numbers from 1 to N Using Recursion
#include <stdio.h>

void printNumbers(int n, int current) {
  if (current <= n) {
    printf("%d ", current);
    printNumbers(n, current + 1);
  }
}

int main() {
  int n;

  printf("Enter a positive integer N: ");
  scanf("%d", &n);

  if (n <= 0) {
    printf("Please enter a positive integer.n");
  } else {
    printNumbers(n, 1);
    printf("n");
  }

  return 0;
}
📤 Output:
Input: 5
Output: Enter a positive integer N: 1 2 3 4 5

Input: 1
Output: Enter a positive integer N: 1

Input: 0
Output: Enter a positive integer N: Please enter a positive integer.

Input: -3
Output: Enter a positive integer N: Please enter a positive integer.

💻 Decimal to Binary Conversion Using Recursion
#include <stdio.h>

void decimalToBinary(int n) {
    if (n > 0) {
        decimalToBinary(n / 2);
        printf("%d", n % 2);
    }
}

int main() {
    int decimal;
    printf("Enter a decimal number: ");
    scanf("%d", &decimal);

    printf("Binary equivalent: ");
    if (decimal == 0) {
        printf("0");
    } else {
        decimalToBinary(decimal);
    }
    printf("n");
    return 0;
}
📤 Output:
Input: 10
Output: Enter a decimal number: Binary equivalent: 1010
Input: 0
Output: Enter a decimal number: Binary equivalent: 0
Input: 25
Output: Enter a decimal number: Binary equivalent: 11001
Input: 127
Output: Enter a decimal number: Binary equivalent: 1111111
Input: 1
Output: Enter a decimal number: Binary equivalent: 1

💻 LCM Using Recursion
#include <stdio.h>

int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
}

int main() {
    int num1, num2;

    printf("Enter two positive integers: ");
    scanf("%d %d", &num1, &num2);

    printf("LCM of %d and %d is %dn", num1, num2, lcm(num1, num2));

    return 0;
}
📤 Output:
Input: 12 18
Output: Enter two positive integers: LCM of 12 and 18 is 36

Input: 25 15
Output: Enter two positive integers: LCM of 25 and 15 is 75

Input: 7 9
Output: Enter two positive integers: LCM of 7 and 9 is 63

💻 GCD/HCF Using Recursion
#include <stdio.h>

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int num1, num2;

  printf("Enter two positive integers: ");
  scanf("%d %d", &num1, &num2);

  printf("GCD of %d and %d is %dn", num1, num2, gcd(num1, num2));

  return 0;
}
📤 Output:
Input: 36 60
Output: Enter two positive integers: GCD of 36 and 60 is 12

💻 Power of a Number Using Recursion
#include <stdio.h>

int power(int base, int exponent) {
    if (exponent == 0) {
        return 1;
    } else if (exponent > 0) {
        return base * power(base, exponent - 1);
    } else {
        return 1 / power(base, -exponent);
    }
}

int main() {
    int base, exponent, result;

    printf("Enter the base number: ");
    scanf("%d", &base);

    printf("Enter the exponent: ");
    scanf("%d", &exponent);

    result = power(base, exponent);

    printf("%d^%d = %dn", base, exponent, result);

    return 0;
}
📤 Output:
Input: 2
Input: 3
Output: 2^3 = 8

Input: 5
Input: 0
Output: 5^0 = 1

Input: 2
Input: -2
Output: 2^-2 = 0

💻 Check Palindrome Using Recursion
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int isPalindrome(char str[], int start, int end) {
    if (start >= end) {
        return 1;
    }
    if (str[start] != str[end]) {
        return 0;
    }
    return isPalindrome(str, start + 1, end - 1);
}

int main() {
    char str[100];

    printf("Enter a string: ");
    scanf("%s", str);

    int length = strlen(str);

    if (isPalindrome(str, 0, length - 1)) {
        printf("%s is a palindromen", str);
    } else {
        printf("%s is not a palindromen", str);
    }

    return 0;
}
📤 Output:
Input: madam
Output: madam is a palindrome

Input: racecar
Output: racecar is a palindrome

Input: hello
Output: hello is not a palindrome

Input: A man, a plan, a canal: Panama
Output: A is not a palindrome

💻 Reverse a String Using Recursion
#include <stdio.h>
#include <string.h>

void reverseString(char *str, int start, int end) {
    if (start >= end) {
        return;
    }
    char temp = str[start];
    str[start] = str[end];
    str[end] = temp;
    reverseString(str, start + 1, end - 1);
}

int main() {
    char str[100];

    printf("Enter a string: ");
    scanf("%s", str);

    int length = strlen(str);
    reverseString(str, 0, length - 1);

    printf("Reversed string: %sn", str);

    return 0;
}
📤 Output:
Input: hello
Output: Reversed string: olleh

Input: world
Output: Reversed string: dlrow

Input: abcdef
Output: Reversed string: fedcba

Input: A
Output: Reversed string: A

Input: racecar
Output: Reversed string: racecar

💻 Sum of Digits Using Recursion
#include <stdio.h>

int sumOfDigits(int n) {
    if (n == 0) {
        return 0;
    }
    return (n % 10) + sumOfDigits(n / 10);
}

int main() {
    int num;
    printf("Enter a positive integer: ");
    scanf("%d", &num);
    if (num < 0) {
        printf("Please enter a positive integer.n");
        return 1;
    }
    printf("Sum of digits of %d is %dn", num, sumOfDigits(num));
    return 0;
}
📤 Output:
Input: 12345
Output: Enter a positive integer: Sum of digits of 12345 is 15

Input: 9876
Output: Enter a positive integer: Sum of digits of 9876 is 30

Input: 0
Output: Enter a positive integer: Sum of digits of 0 is 0

Input: -123
Output: Enter a positive integer: Please enter a positive integer.

💻 Fibonacci Series Using Recursion
#include <stdio.h>

int fibonacci(int n) {
  if (n <= 1) {
    return n;
  }
  return fibonacci(n - 1) + fibonacci(n - 2); // Recursive call
}

int main() {
  int num, i;

  printf("Enter the number of terms: ");
  scanf("%d", &num);

  printf("Fibonacci Series: ");
  for (i = 0; i < num; i++) {
    printf("%d ", fibonacci(i));
  }
  printf("n");

  return 0;
}
📤 Output:
Input: 10
Output: Enter the number of terms: Fibonacci Series: 0 1 1 2 3 5 8 13 21 34

💻 Factorial Using Recursion
#include <stdio.h>

int factorial(int n) {
  if (n == 0) {
    return 1;
  } else {
    return n * factorial(n - 1); // Recursive call
  }
}

int main() {
  int num;

  printf("Enter a non-negative integer: ");
  scanf("%d", &num);

  if (num < 0) {
    printf("Factorial is not defined for negative numbers.n");
  } else {
    printf("Factorial of %d = %dn", num, factorial(num));
  }

  return 0;
}
📤 Output:
Input: 5
Output: Enter a non-negative integer: Factorial of 5 = 120

Input: 0
Output: Enter a non-negative integer: Factorial of 0 = 1

Input: -2
Output: Enter a non-negative integer: Factorial is not defined for negative numbers.

🔧 Recursion

💻 Split Large File into Smaller Files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    char inputFile[100];
    char outputFilePrefix[100];
    long long chunkSize;

    printf("Enter the input file name: ");
    scanf("%s", inputFile);

    printf("Enter the output file prefix: ");
    scanf("%s", outputFilePrefix);

    printf("Enter the chunk size in bytes: ");
    scanf("%lld", &chunkSize);

    FILE *fp = fopen(inputFile, "rb");
    if (fp == NULL) {
        printf("Error opening input file.n");
        return 1;
    }

    int fileCount = 1;
    long long bytesRead = 0;
    unsigned char *buffer = (unsigned char *)malloc(chunkSize);

    if (buffer == NULL) {
        printf("Memory allocation error.n");
        fclose(fp);
        return 1;
    }

    while (1) {
        size_t bytes = fread(buffer, 1, chunkSize, fp);

        if (bytes == 0) {
            break; // End of file
        }

        char outputFileName[200];
        sprintf(outputFileName, "%s_%03d.part", outputFilePrefix, fileCount);

        FILE *outFile = fopen(outputFileName, "wb");
        if (outFile == NULL) {
            printf("Error creating output file.n");
            fclose(fp);
            free(buffer);
            return 1;
        }

        fwrite(buffer, 1, bytes, outFile);
        fclose(outFile);

        bytesRead += bytes;
        fileCount++;
    }

    fclose(fp);
    free(buffer);

    printf("File split successfully.n");

    return 0;
}
📤 Output:
Input: input.txt
Input: output
Input: 1000
Output: Enter the input file name: Enter the output file prefix: Enter the chunk size in bytes: Error opening input file.

💻 Read File in Reverse Order
#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *file;
    char filename[100];
    long file_size;

    printf("Enter the filename: ");
    scanf("%s", filename);

    file = fopen(filename, "r");
    if (file == NULL) {
        perror("Error opening file");
        return 1;
    }

    fseek(file, 0, SEEK_END);
    file_size = ftell(file);

    if (file_size == -1L) {
        perror("Error getting file size");
        fclose(file);
        return 1;
    }

    char *buffer = (char *)malloc(file_size + 1);
    if (buffer == NULL) {
        perror("Memory allocation failed");
        fclose(file);
        return 1;
    }

    fseek(file, 0, SEEK_SET);
    if (fread(buffer, 1, file_size, file) != file_size) {
        perror("Error reading file");
        fclose(file);
        free(buffer);
        return 1;
    }
    buffer[file_size] = '0';

    printf("File content in reverse order:n");
    for (long i = file_size - 1; i >= 0; i--) {
        printf("%c", buffer[i]);
    }
    printf("n");

    fclose(file);
    free(buffer);

    return 0;
}
📤 Output:
Input: test.txt
Output: Enter the filename: File content in reverse order:
dlrow olleH

💻 Append Data to Existing File
#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *fptr;
    char data[100];

    printf("Enter data to append: ");
    scanf(" %[^n]", data);

    fptr = fopen("example.txt", "a"); // Open file in append mode

    if (fptr == NULL) {
        printf("Error opening file!n");
        return 1;
    }

    fprintf(fptr, "%sn", data);

    printf("Data appended successfully!n");

    fclose(fptr);

    return 0;
}
📤 Output:
Input: This is some new data.
Output: Enter data to append: Data appended successfully!

💻 Write Data to CSV File
#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *fp;
    char filename[50];
    char name[50];
    int age;
    float salary;

    printf("Enter the filename to write to (e.g., data.csv): ");
    scanf("%s", filename);

    fp = fopen(filename, "w");

    if (fp == NULL) {
        printf("Error opening file!n");
        return 1;
    }

    printf("Enter name: ");
    scanf("%s", name);
    printf("Enter age: ");
    scanf("%d", &age);
    printf("Enter salary: ");
    scanf("%f", &salary);

    fprintf(fp, "%s,%d,%.2fn", name, age, salary);

    fclose(fp);

    printf("Data written to %s successfully!n", filename);

    return 0;
}
📤 Output:
Input: data.csv
Output: Enter the filename to write to (e.g., data.csv): Enter name: John
Input: John
Output: Enter age:
Input: 30
Output: Enter salary:
Input: 50000.50
Output: Data written to data.csv successfully!

💻 Read CSV File and Process Data
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    FILE *fp;
    char filename[100];
    char line[200];
    char *token;
    int data1, data2;

    printf("Enter the CSV filename: ");
    scanf("%s", filename);

    fp = fopen(filename, "r");

    if (fp == NULL) {
        printf("Error opening file!n");
        return 1;
    }

    // Read header line (optional)
    fgets(line, sizeof(line), fp);

    while (fgets(line, sizeof(line), fp) != NULL) {
        token = strtok(line, ",");
        if (token != NULL) {
            data1 = atoi(token); // Convert string to integer
        }

        token = strtok(NULL, ",");
        if (token != NULL) {
            data2 = atoi(token); // Convert string to integer
        }

        printf("Data 1: %d, Data 2: %dn", data1, data2);
    }

    fclose(fp);
    return 0;
}
📤 Output:
Input: data.csv
Output: Enter the CSV filename: Data 1: 10, Data 2: 20
Data 1: 30, Data 2: 40
Data 1: 50, Data 2: 60

(Assuming data.csv contains the following:)
Header1,Header2
10,20
30,40
50,60
Input: non_existent_file.csv
Output: Enter the CSV filename: Error opening file!