Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please answer the above three questions using C language 7. Write a function in

ID: 3712501 • Letter: P

Question

please answer the above three questions using C language

7. Write a function in 'C to check whether a given string is palindrome or not. (If the string and its reverse are same, the string is said to be palindrome). Do not use any in-built string manipulation functions to implement your function 8. Write a program in C" to draw a circ le of radius 5 cm. Colour the circ le with 'blue' colour. 9. Write a program to create and store an array and write functions to check: (a) the diagonal ee ments are all zero or not (b) the upper triangular elements of the array are all-zero or all non zero. (c) if the upper/lower triangular ele ments of the array are all-zero, store these elements in a one-dimensional array.

Explanation / Answer

//Q1: program to check whether no is pallindrome or not ?using while loop.

// Q 2: C program to draw a circle of 5 unit radius

// C Implementation for drawing circle

#include <graphics.h>

//driving code is:

int main()

{

    /* gm is Graphics mode which is

a computer display mode that

generates image using pixels.

*/

    /* DETECT is a macro defined in

"graphics.h" header file */

    int gd = DETECT, gm;

    /* initgraph initializes the

graphics system by loading a

graphics driver from disk */

    initgraph(&gd, &gm, "");

    // circle fuction

    circle(100, 100, 5);

    getch();

    /* closegraph function closes the

graphics mode and deallocates

all memory allocated by */

    // graphics system .

    closegraph();

    return 0;

}

//Q 3: To make an 2D array and check some constraints on it

#include<stdio.h>

#include<conio.h>

int main()

{

int arr[10][10];

int i=0,j=0,n;

printf("enter no of rows and no of columns in array make sure they should de same");

scanf("%d",&n);

// storing elements in array

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

scanf("%d",&arr[i][j]);

}

}

// Now we will check whether it is all 0's in diagonal or not.

// program to check whether matrix is upper triangular or not .

#include <stdio.h>

int main()

{

    int A[10][10],i,j,m,n;

    int row, col, isUpper;

    printf("Enter no. of rows :: ");

scanf("%d", &m);

printf(" Enter no. of cols :: ");

scanf("%d",&n);

printf(" Enter values to the matrix :: ");

for (i = 0; i < m; i++)

{

            for (j = 0; j < n; j++)

            {

                 printf(" Enter a[%d][%d] value :: ",i,j);

                 scanf("%d", &A[i][j]);

        }

    }

    printf(" The given matrix is :: ");

        for (i = 0; i < m; ++i)

        {

            for (j = 0; j < n; ++j)

            {

                printf(" %d", A[i][j]);

            }

            printf(" ");

        }

    /*

     * Checks whether the matrix is Upper triangular

     */

    isUpper = 1;

    for(row=0; row<m; row++)

    {

        for(col=0; col<n; col++)

        {

            /*

             * If elements below the main diagonal (col<row)

             * is not equal to zero then it is not upper triangular matrix

             */

            if(col<row && A[row][col]!=0)

            {

                isUpper = 0;

            }

        }

    }

    /*

     * If it is upper triangular matrix

     */

    if(isUpper==1)

    {

        printf(" This is a Upper triangular matrix. ");

        for(row=0; row<m; row++)

        {

            for(col=0; col<n; col++)

            {

                if(A[row][col] != 0)

                {

                    printf(" %d ", A[row][col]);

                }

                else

                {

                    printf(" ");

                }

            }

            printf(" ");

        }

    }

    else

    {

        printf(" This is Not a Upper triangular matrix.");

    }

    return 0;

}

// program to check given matrix is lower triangular or not.

#include <stdio.h>

int main()

{

    int A[10][10],i,j,m,n;

    int row, col, isLower;

    printf("Enter no. of rows :: ");

scanf("%d", &m);

printf(" Enter no. of cols :: ");

scanf("%d",&n);

printf(" Enter values to the matrix :: ");

for (i = 0; i < m; i++)

{

            for (j = 0; j < n; j++)

            {

                 printf(" Enter a[%d][%d] value :: ",i,j);

                 scanf("%d", &A[i][j]);

        }

    }

    isLower = 1;

    for(row=0; row<m; row++)

    {

        for(col=0; col<n; col++)

        {

            /*

             * If elements above main diagonal(col>row)

             * is not equal to zero(A[row][col]!=0)

             */

            if(col>row && A[row][col]!=0)

            {

                isLower = 0;

            }

        }

    }

    if(isLower == 1)

    {

        printf(" Matrix is Lower triangular matrix: ");

        /*

         * Prints elements of lower triangular matrix

         */

        for(row=0; row<m; row++)

        {

            for(col=0; col<n; col++)

            {

                if(A[row][col]!=0)

                {

                    printf(" %d", A[row][col]);

                }

            }

            printf(" ");

        }

    }

    else

    {

        printf(" Matrix is not a Lower triangular matrix");

    }

    return 0;

}

  

// C Implementation for drawing circle

#include <graphics.h>

//driving code is:

int main()

{

    /* gm is Graphics mode which is

a computer display mode that

generates image using pixels.

*/

    /* DETECT is a macro defined in

"graphics.h" header file */

    int gd = DETECT, gm;

    /* initgraph initializes the

graphics system by loading a

graphics driver from disk */

    initgraph(&gd, &gm, "");

    // circle fuction

    circle(100, 100, 5);

   setfillsyle(HATCH_FILL,BLUE);      floodfill(100,100,BLUE);

    getch();

    /* closegraph function closes the

graphics mode and deallocates

all memory allocated by */

    // graphics system .

    closegraph();

    return 0;

}

//Q 3: To make an 2D array and check some constraints on it

#include<stdio.h>

#include<conio.h>

int main()

{

int arr[10][10];

int i=0,j=0,n;

printf("enter no of rows and no of columns in array make sure they should de same");

scanf("%d",&n);

// storing elements in array

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

scanf("%d",&arr[i][j]);

}

}

// Now we will check whether it is all 0's in diagonal or not.

  #include<srdio.h>  int main ()  {  int n,b=0;  printf("%d",n);  int a[n][n];  for (int i=0;i<n;i++)      for (int j=0;j<n;j++)  {      printf("%d",a[i][j]);  }  int j,i;  for(int br=0; br<2*n-1; br++)  {         if(br<n) {        i=br;       j = 0;     }     else {        i = n-1;       j = (br+1)%n;     }     bool p=1;     while(i>=0 && j<n)     {        if(a[i][j]!=0)          { p=0;          break;}        i--;       j++;     }     if(p)      b++;   }    printf(" ");  printf("%d",b);    return 0;  }

// program to check whether matrix is upper triangular or not .

#include <stdio.h>

int main()

{

    int A[10][10],i,j,m,n;

    int row, col, isUpper;

    printf("Enter no. of rows :: ");

scanf("%d", &m);

printf(" Enter no. of cols :: ");

scanf("%d",&n);

printf(" Enter values to the matrix :: ");

for (i = 0; i < m; i++)

{

            for (j = 0; j < n; j++)

            {

                 printf(" Enter a[%d][%d] value :: ",i,j);

                 scanf("%d", &A[i][j]);

        }

    }

    printf(" The given matrix is :: ");

        for (i = 0; i < m; ++i)

        {

            for (j = 0; j < n; ++j)

            {

                printf(" %d", A[i][j]);

            }

            printf(" ");

        }

    /*

     * Checks whether the matrix is Upper triangular

     */

    isUpper = 1;

    for(row=0; row<m; row++)

    {

        for(col=0; col<n; col++)

        {

            /*

             * If elements below the main diagonal (col<row)

             * is not equal to zero then it is not upper triangular matrix

             */

            if(col<row && A[row][col]!=0)

            {

                isUpper = 0;

            }

        }

    }

    /*

     * If it is upper triangular matrix

     */

    if(isUpper==1)

    {

        printf(" This is a Upper triangular matrix. ");

        for(row=0; row<m; row++)

        {

            for(col=0; col<n; col++)

            {

                if(A[row][col] != 0)

                {

                    printf(" %d ", A[row][col]);

                }

                else

                {

                    printf(" ");

                }

            }

            printf(" ");

        }

    }

    else

    {

        printf(" This is Not a Upper triangular matrix.");

    }

    return 0;

}

// program to check given matrix is lower triangular or not.

#include <stdio.h>

int main()

{

    int A[10][10],i,j,m,n;

    int row, col, isLower;

    printf("Enter no. of rows :: ");

scanf("%d", &m);

printf(" Enter no. of cols :: ");

scanf("%d",&n);

printf(" Enter values to the matrix :: ");

for (i = 0; i < m; i++)

{

            for (j = 0; j < n; j++)

            {

                 printf(" Enter a[%d][%d] value :: ",i,j);

                 scanf("%d", &A[i][j]);

        }

    }

    isLower = 1;

    for(row=0; row<m; row++)

    {

        for(col=0; col<n; col++)

        {

            /*

             * If elements above main diagonal(col>row)

             * is not equal to zero(A[row][col]!=0)

             */

            if(col>row && A[row][col]!=0)

            {

                isLower = 0;

            }

        }

    }

    if(isLower == 1)

    {

        printf(" Matrix is Lower triangular matrix: ");

        /*

         * Prints elements of lower triangular matrix

         */

        for(row=0; row<m; row++)

        {

            for(col=0; col<n; col++)

            {

                if(A[row][col]!=0)

                {

                    printf(" %d", A[row][col]);

                }

            }

            printf(" ");

        }

    }

    else

    {

        printf(" Matrix is not a Lower triangular matrix");

    }

    return 0;

}