C language basic to Advance
2K subscribers
16 photos
2 videos
69 links
Download Telegram
20 Questions on C loops:
`1. Write a C program to print all even numbers between 1 and 100 using a for loop.

2. Write a C program to calculate the sum of all odd numbers between 1 and 50 using a while loop.

3. Write a C program to print the multiplication table of a given number using a for loop.

4. Write a C program to find the factorial of a given number using a for loop.

5. Write a C program to check if a given number is prime or not using a for loop.

6. Write a C program to print the Fibonacci series up to a given number using a for loop.

7. Write a C program to find the sum of all elements in an array using a for loop.

8. Write a C program to find the largest element in an array using a for loop.

9. Write a C program to find the smallest element in an array using a for loop.

10. Write a C program to reverse an array using a for loop.

11. Write a C program to sort an array in ascending order using a for loop.

12. Write a C program to sort an array in descending order using a for loop.

13. Write a C program to find the sum of the digits of a given number using a while loop.

14. Write a C program to check if a given number is a palindrome or not using a while loop.

15. Write a C program to convert a decimal number to binary using a while loop.

16. Write a C program to convert a binary number to decimal using a while loop.

17. Write a C program to find the GCD of two numbers using a while loop.

18. Write a C program to find the LCM of two numbers using a while loop.

19. Write a C program to print all Armstrong numbers between 1 and 1000 using a for loop.

20. Write a C program to print all perfect numbers between 1 and 1000 using a for loop.`


Answers:
https://t.me/C_Codes_pro/301
👍31🔥1
// Dowhile loop to ask user for input until a valid number is entered:
#include <stdio.h>

int main() {
   int num;
  
   do {
      printf("Enter a number between 1 and 10: ");
      scanf("%d", &num);
   } while(num < 1 || num > 10);
  
   printf("You entered: %d", num);
  
   return 0;
}

// @C_Codes_pro
//To check leap year
#include<stdio.h>
int main() {
    int year;
    printf("Enter a year that you want to check:");
    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;
}

// @C_Codes_pro
Give code sujjestion here 👇
Learn in 55 seconds
How to run codes in telegram 👇
https://t.me/logicBots/163
// Decimal to Hexadecimal By C
#include<stdio.h>

int main()
{
    int rem,num,i=1,j;
    char Hexa[50];
    
    printf("Enter Decimal no: ");
    scanf("%d", &num);
   
    if(num!=0){
    while(num!=0){
    rem = num % 16;
   
    if(rem<10)
    rem=rem+48;
   
    else
    rem=rem+55;
   
    Hexa[i++]=rem;
    num=num/16;
    }}
    else{
    printf("0");
    }
    printf("\nHexadecimal Number is ");
    for(j=i;0<j;j--){
    printf("%c",Hexa[j]);
    }
    return 0;
} // @C_Codes_pro
👍3
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;
}