C language basic to Advance
2K subscribers
16 photos
2 videos
69 links
Download Telegram
Ab aap log apna khud ka Compiler bot bana sakte hain easily 🥳🥳🔥
Apne manpasand name aur username se

Create your own
By using @CloneCompiler_bot

See full details: Click Here
👍1🥰1
// 1 strlen() - String Length:
#include <stdio.h>
#include <string.h>

int main() {
char str[] = "Hello";
int length = strlen(str);
printf("Length of the string is: %d\n", length);
return 0;
}
// 2 strcpy() - String Copy:
#include <stdio.h>
#include <string.h>

int main() {
char source[] = "Hello";
char destination[20];
strcpy(destination, source);
printf("Copied string is: %s\n", destination);
return 0;
}
👍2
// 3 strcmp() - String Compare:
#include <stdio.h>
#include <string.h>

int main() {
char str1[] = "Hello";
char str2[] = "Hello";
if (strcmp(str1, str2) == 0) {
printf("Strings are equal\n");
} else {
printf("Strings are not equal\n");
}
return 0;
}
// strcat() - String Concatenation:
#include <stdio.h>
#include <string.h>

int main() {
char str1[20] = "Hello";
char str2[] = " World!";
strcat(str1, str2);
printf("Concatenated string is: %s\n", str1);
return 0;
}

//Learn coding:
// https://t.me/addlist/2UhsQW_cGzkxMzg1
C language basic to Advance pinned «Notes 📝 : Telegram.me/BCA_Sem1_Notes Telegram.me/BCA_Sem2_Notes Telegram.me/BCA_Sem3_Notes Telegram.me/BCA_Sem4_Notes Telegram.me/BCA_Sem5_Notes Telegram.me/BCA_Sem6_Notes Code practice Channels: Telegram.me/C_Codes_pro Telegram.me/CPP_Codes_pro Telegram…»
/*Matrix!!
🔴(AB)'=B'A' */
#include<stdio.h>
#define MAX 10
void transpose(int arr[][MAX], int transpose[][MAX], int row, int column) {
    for(int a = 0; a < column; a++) {
        for(int b = 0; b < row; b++) {
            transpose[a][b] = arr[b][a];
        }
    }
}
void Multiplication(int arr1[][MAX], int arr2[][MAX], int result[][MAX], int row1, int column1, int row2, int column2) {
    if(column1 != row2) {
        printf("Multiplication is not possible.");
        return;
    }   
    for(int a = 0; a < row1; a++) {
        for(int b = 0; b < column2; b++) {
            int sum = 0;
            for(int k = 0; k < column1; k++) {
                sum += arr1[a][k] * arr2[k][b];
            }
            result[a][b] = sum;
        }
    }
}
void printMatrix(int arr[][MAX], int row, int column) {
    for(int a = 0; a < row; a++) {
        for(int b = 0; b < column; b++) {
            printf("%d ", arr[a][b]);
        }
        printf("\n");
    }
}
int main() {
    int r1, c1, r2, c2;
    int ar1[MAX][MAX], ar2[MAX][MAX], result[MAX][MAX], transpose1[MAX][MAX], transpose2[MAX][MAX], transpose3[MAX][MAX];

    printf("Enter rows and columns of the first matrix (max 10): ");
    scanf("%d %d", &r1, &c1);

    printf("Enter rows and columns of the second matrix (max 10): ");
    scanf("%d %d", &r2, &c2);
   if(c1 != r2) {
        printf("Error!! Wrong row and column");
        return 0;
    }
   else{
    printf("Enter elements of the first matrix (A):\n");
    for(int a = 0; a < r1; a++) {
        for(int b = 0; b < c1; b++) {
            scanf("%d", &ar1[a][b]);
        }
    }
    printf("Enter elements of the second matrix (B):\n");
    for(int a = 0; a < r2; a++) {
        for(int b = 0; b < c2; b++) {
            scanf("%d", &ar2[a][b]);
        }
    }
    printf("\nLHS:\nMultiplication of Matrix (AB):\n");
    Multiplication(ar1, ar2, result, r1, c1, r2, c2);
    printMatrix(result, r1, c2);

    printf("Transpose of Matrix (AB)':\n");
    transpose(result, transpose3, r1, c2);
    printMatrix(transpose3, c2, r1);

    printf("\nRHS:\nTranspose of Matrix (A)'\n");
    transpose(ar1, transpose1, r1, c1);
    printMatrix(transpose1, c1, r1);

    printf("Transpose of Matrix (B)'\n");
    transpose(ar2, transpose2, r2, c2);
    printMatrix(transpose2, c2, r2);

    printf("Multiplication of Matrices (B'A'):\n");
    Multiplication(transpose2, transpose1, result, c2, r2, c1, r1);
    printMatrix(result, c2, r1);
  }

    return 0;
}
👍3
"Start"

int a = 6;
Pt"This is short c for this bot\nYou can practice in @io_coding group using short codes\n\nFor printf(); you can simply write pt and then your code \n\nRun code using /cc and you can easily convert this code in real c code by using /rcc command \nvar=%d", a

"End"
Answers of all these 20 loop questions
https://t.me/C_Codes_pro/184
👇👇👇
// 1. Print all even numbers between 1 and 100 using a for loop:
#include <stdio.h>
int main() {
for (int i = 2; i <= 100; i += 2) {
printf("%d ", i);
}
return 0;
}
// 2. Calculate the sum of all odd numbers between 1 and 50 using a while loop:
#include <stdio.h>

int main() {
int sum = 0;
int num = 1;
while (num <= 50) {
if (num % 2 != 0) {
sum += num;
}
num++;
}
printf("Sum of odd numbers: %d", sum);
return 0;
}
👍1
// 3. Print the multiplication table of a given number using a for loop:
#include <stdio.h>

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

for (int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", number, i, number * i);
}
return 0;
}
// 4. Find the factorial of a given number using a for loop:
#include <stdio.h>

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

int factorial = 1;
for (int i = 1; i <= number; i++) {
factorial *= i;
}
printf("Factorial of %d = %d", number, factorial);
return 0;
}
// 5. Check if a given number is prime or not using a for loop:
#include <stdio.h>

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

int isPrime = 1; // Assume it's prime initially

for (int i = 2; i <= number / 2; i++) {
if (number % i == 0) {
isPrime = 0; // It's not prime
break;
}
}

if (isPrime == 1 && number > 1) {
printf("%d is a prime number.", number);
} else {
printf("%d is not a prime number.", number);
}

return 0;
}
// 6. Write a C program to print the Fibonacci series up to a given number using a for loop:
#include <stdio.h>

int main() {
int n;
printf("Enter the number of terms for Fibonacci series: ");
scanf("%d", &n);

int first = 0, second = 1, next;

printf("Fibonacci Series: %d %d ", first, second);

for (int i = 2; i < n; i++) {
next = first + second;
printf("%d ", next);
first = second;
second = next;
}

return 0;
}
1
// 7. Write a C program to find the sum of all elements in an array using a for loop:
#include <stdio.h>

int main() {
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);

int arr[size];
printf("Enter %d elements for the array: ", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

int sum = 0;

for (int i = 0; i < size; i++) {
sum += arr[i];
}

printf("Sum of array elements: %d", sum);
return 0;
}
👍1
// 8. Write a C program to find the largest element in an array using a for loop:
#include <stdio.h>

int main() {
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);

int arr[size];
printf("Enter %d elements for the array: ", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

int max = arr[0];

for (int i = 1; i < size; i++) {
if (arr[i] > max) {
max = arr[i];
}
}

printf("Largest element in the array: %d", max);
return 0;
}
// 9. Write a C program to find the smallest element in an array using a for loop:
#include <stdio.h>

int main() {
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);

int arr[size];
printf("Enter %d elements for the array: ", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

int min = arr[0];

for (int i = 1; i < size; i++) {
if (arr[i] < min) {
min = arr[i];
}
}

printf("Smallest element in the array: %d", min);
return 0;
}
// 10. Write a C program to reverse an array using a for loop:
#include <stdio.h>

int main() {
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);

int arr[size];
printf("Enter %d elements for the array: ", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

printf("Original array: ");
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}

printf("\nReversed array: ");
for (int i = size - 1; i >= 0; i--) {
printf("%d ", arr[i]);
}

return 0;
}
// 11. Write a C program to sort an array in ascending order using a for loop:
#include <stdio.h>

int main() {
int size;
printf("Enter the size of the array: ");
scanf("%d", &size);

int arr[size];
printf("Enter %d elements for the array: ", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

// Sorting logic (bubble sort)
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

printf("Array in ascending order: ");
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}

return 0;
}