Sunday, December 25, 2022

C Programming. Spash matrix.

 Spash matrix.


#include<stdio.h>

int main() {
    int r, c, count=0;;
    printf("Enter the no. of rows and columns for sqare matrix : ");
    scanf("%d%d",&r,&c);
    int mat[r][c];
    // Taking input from the user.
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++ ){
            printf("matrix[%d][%d] = ", i+1,j+1);
            scanf("%d",&mat[i][j]);
            if (mat[i][j]==0){
                count++;
            }
        }
    }
    if (count>c*r/2){
        printf("Spash.");
    }
    else{
        printf("Not spash.");
    }
    return 0;
}
   

C Programming. Arranging columns of a matrix.

 Arranging columns of a matrix.


#include<stdio.h>

int main() {
    int r, c, t;
    printf("Enter the no. of rows and columns : ");
    scanf("%d%d",&r,&c);
    int mat[r][c];
    // Taking input from the user.
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++ ){
            printf("matrix[%d][%d] = ", i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }

    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            for (int k=j+1; k<r; k++){
                if (mat[j][i]>mat[k][i]){
                    t=mat[j][i];
                    mat[j][i]=mat[k][i];
                    mat[k][i]=t;
                }
            }
        }
    }
    printf("After arranging the columns... \n");
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            printf("%d ",mat[i][j]);
        }printf("\n");
    }
    return 0;
}

C Programming. Arranging rows of a matrix.

 Arranging rows of a matrix.


#include<stdio.h>

int main() {
    int r, c, t;
    printf("Enter the no. of rows and columns : ");
    scanf("%d%d",&r,&c);
    int mat[r][c];
    // Taking input from the user.
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++ ){
            printf("matrix[%d][%d] = ", i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }

    // main logic.

    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            for (int k=j+1; k<c; k++){
                if (mat[i][j]>mat[i][k]){
                    t=mat[i][j];
                    mat[i][j]=mat[i][k];
                    mat[i][k]=t;
                }
            }
        }
    }
    printf("After arranging rows...\n");
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            printf("%d ",mat[i][j]);
        }printf("\n");
    }
    return 0;
}

C Programming. Inter change two columns of a matrix.

Inter change two columns of a matric.


#include<stdio.h>

int main() {
    int r, c, t, a, b;
    printf("Enter the no. of rows and columns : ");
    scanf("%d%d",&r,&c);
    int mat[r][c];
    // Taking input from the user.
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++ ){
            printf("matrix[%d][%d] = ", i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }
    printf("Which two columns you want to interchange : ");
    scanf("%d%d",&a,&b);
    for (int i=0; i<r; i++){
        t=mat[i][a];
        mat[i][a]=mat[i][b];
        mat[i][b]=t;
    }
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            printf(" %d ",mat[i][j]);
        }printf("\n\n");
    }

    return 0;

} 


C programming. Inter change two rows of a matrix.

 Inter change two rows of a matrix.

 #include<stdio.h>


int main() {
    int r, c, t, a, b;
    printf("Enter the no. of rows and columns : ");
    scanf("%d%d",&r,&c);
    int mat[r][c];
    // Taking input from the user.
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++ ){
            printf("matrix[%d][%d] = ", i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }
    printf("Which two columns you want to interchange : ");
    scanf("%d%d",&a,&b);
    for (int i=0; i<c; i++){
        t=mat[a][i];
        mat[a][i]=mat[b][i];
        mat[b][i]=t;
    }
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            printf(" %d ",mat[i][j]);
        }printf("\n\n");
    }

    return 0;
}

Sunday, December 18, 2022

C Programming. To do arithmetic operation using switch case.

 

To do arithmetic operation using switch case.




The output should be like this.....

                Enter the first number : 5
                Enter the second number : 2
                Enter the operator : +
                Ans = 7

C programming. How to print reverse of a number.

 C Program to print reverse of a number.

#include<stdio.h>
int main() {
    int num, rev=0, rem;
    printf("Enter a number : ");
    scanf("%d",&num);
    while (num>0){
        rem = num%10;
        rev = rev*10+rem;
        num /= 10;
    }
    printf("The reverse of the number is : %d",rev);
    return 0;
}

The output should be like this...

                    Enter a number : 12345
                    The reverse of the number is : 54321
                    

C Programming. Find the sum of all digits of a number.

 C Program to print sum of all digits of a number.




The output should be like this...

                Enter a number : 12345
                The sum of digits : 15

Wednesday, December 14, 2022

How to print "Hello World" in C language.

 This is my first blog and this is about how to print "Hello World" in C language.


Source Code :-


#include<stdio.h>
int main() {
    printf("Hello World");
    return 0;
}

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...