Author: pawan joshi

  • // apna program to find reverse of an array using dma

    include

    include

    int main() {
    int *p,i,j,n,sum=0,avg=0,temp;
    printf(“Enter the number of elements to store:\n”);
    scanf(“%d”,&n);

    printf("Enter the elements to store:\n");
    
    
    p=(int*)malloc(n*sizeof(int));
    
        for(i=0;i<n;i++){
        scanf("%d",(p+i));
        }
    
        for(i=0,j=n-1;i<n/2;i++,j--){
            temp=*(p+i);
            *(p+i)=*(p+j);
            *(p+j)=temp;
        }
    
        for(i=0;i<n;i++){
        printf("%d ",*(p+i));
        }
    
        printf("\n");
    
    return 0;

    }

  • // program to count the even and odd numbers in an integer

    // program to count the even and odd numbers in an integer

    include

    void new(int *a, int *even, int *odd);
    int main()
    {
    int a, b, n, even=0, odd=0;
    int arr[50];
    printf(“Enter the limit :\n”);

        scanf("%d",&n);
    
        printf("Enter the array elements :\n");
    
        for (int i =0 ; i<n; i++){
        scanf("%d", &arr[i]);
        new(&arr[i], &even, &odd);
        }
    
        printf("********______ *********** \n\n");
    
        printf(" EVEN COUNT : %d\n ",even);
        printf("ODD COUNT : %d\n\n\n ",odd);
    
        printf("********______ *********** \n\n");
    
        return 0;

    }
    void new(int *a, int *even, int *odd){

    if(*a % 2==0){
    (*even)++;
    }
    else{
    (*odd)++;
    }

    }

  • // program for swap two number uwithout using 3rd variable

    // program for swap two number uwithout using 3rd variable

    include

    void new(int *a, int *b);
    int main()
    {
    int a,b;
    printf(“Enter number 1: \n”);
    scanf(“%d”,&a);
    printf(“Enter number 2: \n”);
    scanf(“%d”,&b);

        printf("ORIGINAL Value of a : %d\n ",a);
        printf("ORIGINAL Value of b : %d\n ",b);
    
        new(&a, &b);
    
        printf("********  SWAPPED VALUES  *********** ");
    
        printf("New Value of a : %d\n ",a);
        printf("New Value of b : %d\n ",b);
    
    
        return 0;

    }
    void new(int *a, int *b ){

    // a=a^*b;
    // *b=a^b;
    // a=a^*b;

    *a=*a+*b-(*b=*a);
    return ;

    }

  • // program for call by reference verification

    // program for call by reference verification

    include

    void new(int *n);
    int main()
    {
    int n,a;
    printf(“Enter a number : \n”);
    scanf(“%d”,&n);
    printf(“The entered number is : %d\n “,n);

        new(&n);
    
        printf("CHECKING THE VALUE of n : %d",n);
    
    
        return 0;

    }
    void new(int *n){
    *n=n+5; printf(“The new value of [ a ] is : %d \n”,n);
    return ;
    }

  • // program for call by value verification

    // program for call by value verification

    include

    void new(int);
    int main()
    {
    int n,a;
    printf(“Enter a number : \n”);
    scanf(“%d”,&n);
    printf(“The entered number is : %d\n “,n);
    new(n);

        printf("CHECKING THE VALUE of n : %d\n\n",n);
    
    
        return 0;

    }
    void new(int n){
    n=n+5;
    printf(“The new value of [ a ] is : %d \n”,n);
    return ;
    }

  • 3

    include

    int main(){
    int i,j,r,c,f=0;
    printf(“Enter the no of rows and columns:\n”);
    scanf(“%d%d”,&r,&c);

    int m[r][c];
    printf("Enter the elments of matrix:\n");
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&m[i][j]);
        }
    }
    
      for(i=0;i<r;i++){
        for(j=0;j<c;j++){
    
            if(i<j && m[i][j]!=0){
                    f=1;
                    break;
                }
    
    
        }
    }

    if(f==0){
    printf(“Lower Triangular\n”);

    }
    else{

    printf("Not a Triangular martix");

    }
    return 0;
    }

  • 2

    include

    int main(){
    int i,j,r,c,f=0;
    printf(“Enter the no of rows and columns:\n”);
    scanf(“%d%d”,&r,&c);

    int m[r][c];
    printf("Enter the elments of matrix:\n");
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&m[i][j]);
        }
    }
    
      for(i=0;i<r;i++){
        for(j=0;j<c;j++){
    
            if(i>j && m[i][j]!=0){
                    f=1;
                    break;
                }
    
    
        }
    }

    if(f==0){
    printf(“Upper Triangular\n”);

    }
    else{

    printf("Not a Upper Triangular martix");

    }
    return 0;
    }

  • 1

    include

    int main(){
    int i,j,r,c;
    printf(“Enter the no of rows and columns:\n”);
    scanf(“%d%d”,&r,&c);

    int m[r][c];
    printf("Enter the elments of matrix:\n");
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&m[i][j]);
        }
    }
    
    int large=m[0][0];
    int small=m[0][0];
    
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
    
            if(m[i][j]>large){
                large=m[i][j];
            }
    
            if(m[i][j]<small){
                small=m[i][j];
            }
    
        }
    }
    
     printf("Large : %d\n Small : %d\n",large,small);
    return 0;

    }

  • SADDLE POINT

    include

    int main()
    {
    int i,j,r,c,small,large;

    printf("Enter number of rows and coloumns\n");
    scanf("%d%d", &r, &c);
    
    int m1[r][c];
    
    printf("Enter the elements of matrix :\n");
    
    for(i=0; i<r; i++) {
        for(j=0; j<c; j++) {
            scanf("%d",&m1[i][j]);
        }
    }
    
    
    printf("Entered matrices is: \n\n");
    
    for(i=0; i<r; i++) {
        for(j=0; j<c;j++) {
            printf("%d ",m1[i][j]);
        }
    printf("\n");
    
    }

    //LOGIC PART – Small nikalne ka

    small=m1[0][0];
    
    for(i=0; i<r; i++) {
    
        for(j=1; j<c;j++) {
    
            if(m1[i][j]<small){
            small=m1[i][j];
    
            }
    
            //small kon si memory address hai pata kiya 
    
            for(j=0; j<c;j++) {
    
            if(m1[i][j]==small){
            break;
    
            }
           }
    
    //LOGIC PART - jo small wala column hai kya usme wo largest hai ( in that column )
    
    large=small;
    
    
            for(i=1; i<r; i++) {
    
             if(large<m1[i][j]){
    
            large=m1[i][j];
    
            }
        }
    
        if (large==small){
        printf("%d is the saddle point in a matrix",small);
    
    }
    
        }
    }
    
    
    
    
    
    
    return 0;

    }

  • 4.c

    #include <stdio.h>

    int main()

    {

        int i,j,r,c,sum;

        printf(“Enter number of rows and coloumns\n”);

        scanf(“%d%d”, &r, &c);

        int m1[r][c];

        printf(“Enter the elements of matrix :\n”);

        for(i=0; i<r; i++) {

            for(j=0; j<c; j++) {

                scanf(“%d”,&m1[i][j]);

            }

        }

        printf(“Entered matrices is: \n\n”);

        for(i=0; i<r; i++) {

            for(j=0; j<c;j++) {

                printf(“%d “,m1[i][j]);

            }

        printf(“\n”);

        }

    //LOGIC PART

        sum=0;

        for(i=0; i<r; i++) {

            for(j=0; j<c;j++) {

                if(i==j){

                sum += m1[i][j];

                }

            }

        }

        printf(“The sum of Principal diagonal is : %d\n”,sum);

        sum=0;

        for(i=0; i<r; i++) {

            for(j=0; j<c;j++) {

                 if(i+j==r-1){

                sum += m1[i][j];

                }

            }

        }

        printf(“The sum of Secondary diagonal is : %d\n”,sum);

        return 0;

    }