C language basic to Advance
2K subscribers
16 photos
2 videos
69 links
Download Telegram
//Transpose of Matrix..
#include<stdio.h>
int main() {
    int row, column;
    printf("Enter row and column of Matrix:");
    scanf("%d %d",&row,&column);
      if (row <= 0 || column <= 0) {
           printf("Error!! Row and column values must be positive integers.\n");
           return 1;
           
    }
    int a[row][column];
    for(int r=0; r<row; r++) {
        for(int c=0; c<column; c++) {
            printf("Enter element A[%d%d] :",r,c);
            scanf("%d",&a[r][c]);
        }
    }
    printf("\nMatrix:\n");
    for(int r=0; r<row; r++) {
        for(int c=0; c<column; c++) {
            printf("%d  ",a[r][c]);
        }
        printf("\n");
    }

    printf("\nTranspose of Matrix:\n");
    for(int r=0; r<column; r++) {
        for(int c=0; c<row; c++) {
            printf("%d  ",a[c][r]);
        }
        printf("\n");
    }


    return 0;
}
//Fibonacci sequence and Factorial by using recursion..
#include <stdio.h>
int fibo(int a) {
if(a==0)
return 0;
else if(a==1||a==2)
return 1;
else return fibo(a-1)+fibo(a-2);
}
void printFiboSeries(int n, int f) {
if (f < n) {
printf("%d ",fibo(f));
printFiboSeries(n, f + 1);
}
}
int fact(int b) {
if(b==0)
return 1;
else
return (b*fact(b-1));
}
int main() {
int n,f;
printf("Enter the terms:");
scanf("%d",&n);
printf("Fibonacci sequence:");
printFiboSeries(n,0);
printf("\nFactorial of given number:%d",fact(n));
return 0;

}
//LCM and HCF
#include<stdio.h>
int main() {
int a, b, i, hcf=1,max;
printf("Enter first number:");
scanf("%d",&a);
printf("Enter second number:");
scanf("%d",&b);

for(i = 1; i <= a || i <= b; i++) {
if( a%i == 0 && b%i == 0 )
hcf = i;
}
max=(a>b)?a:b;
while(1) {
if(max%a==0 && max%b==0) {
break;
}
max++;
}
printf("LCM = %d\n",max);
printf("HCF = %d", hcf);


return 0;
}
C language for beginners : https://www.youtube.com/playlist?list=PLjEYzWkdEvxv5Byb-QnlQrjsuDuhpXX1G

Regular videos: continue with me till full c language
Expressions and operators in c detailed

Topics covered:
00: 00 introduction to c operaters

02: 00 All c language operators in detail practically explained

02: 03 Airthmetic operators in c

03: 33 Relational operators in c

05: 07 Logical operators in c

06: 50 Assignment operators or shortcuts in c

09: 00 increment decrement operators in c

09: 41 sizeof and ternary operator in c

10: 59 comma operator in c

11: 44 bitwise operator, address of, pointer dereference, member access operators

12: 23 expressions in c language

https://youtu.be/qerhr7-a9TM?si=4v1uf0S6Nxep_pHA
👍2
#include <stdio.h>

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

printf("Enter first number: ");
scanf("%d", &num1);

printf("Enter second number: ");
scanf("%d", &num2);

sum = num1 + num2;

printf("Sum of %d and %d is %d\n", num1, num2, sum);

return 0;
}



/* * * * * * * * * * * * * * * * * * * *
How to take user input:
https://youtu.be/VbaKf9FwnDk

Video have a task
* * * * * * * * * * * * * * * * * * * */
👍3
// 1 to 100 numbers

#include <stdio.h>

int main() {
   
    for (int i = 1; i <= 10; i++) {
        for (int j = 0; j < 10; j++)
            if(i < 10)
                 printf("%d%d ", j, i);
             else
                 printf("%d ", (j + 1) * 10);
        printf("\n");
    }
   
    return 0;
}
👍2
// 1. For loop to print numbers from 1 to 10:

#include <stdio.h>

int main() {
   int i;
  
   for(i=1; i<=10; i++) {
      printf("%d ", i);
   }
  
   return 0;
}
👍1
// 2. While loop to print even numbers from 2 to 20:

#include <stdio.h>

int main() {
   int i = 2;
  
   while(i <= 20) {
      printf("%d ", i);
      i += 2;
   }
  
   return 0;
}
👍1
// 4. Nested for loop to print a multiplication table:

#include <stdio.h>

int main() {
   int i, j;
  
   for(i=1; i<=10; i++) {
      for(j=1; j<=10; j++) {
         printf("%d x %d = %d\n", i, j, i*j);
      }
      printf("\n");
   }
  
   return 0;
}
👍2
// 5. Break statement in a while loop to exit the loop when a certain condition is met:

#include <stdio.h>

int main() {
   int i = 1, num;
  
printf("Enter number less than 1000 : ");
scanf("%d", &num);

   while(i <= 1000) {
      printf("%d ", i);
      if(i == num) {
         break;
      }
      i++;
   }
  
   return 0;
}
👍1