wap to store data of sparse matrix efficiently.

#include<stdio.h>
main()
{
int arr[100][100],arr1[100][3],i,j,m,n,a=1,b=0;
printf("enter the no of columns and rows\n");
scanf("%d%d",&m,&n);
arr1[0][0]=m;arr1[0][1]=n;
printf("enter the elements of the matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
scanf("%d",&arr[i][j]);
if(arr[i][j]!=0)
{
arr1[a][b]=i;
arr1[a][b+1]=j;
arr1[a][b+2]=arr[i][j];
a++;
}
}
arr1[0][2]=a-1;
printf("the sparse matrix is as follows\n");
for(i=0;i<a;i++){
for(j=0;j<3;j++)
printf("%d\t",arr1[i][j]);
printf("\n");}
}

wap to find the second largest element from an array.

#include<stdio.h>
main()
{
int i,n,arr[100],a=0,b=0;
printf("enter the no of elements in the array\n");
scanf("%d",&n);
printf("enter the elements of the array\n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=1;i<n;i++)
if(arr[a]<arr[i])
{
b=arr[a];
a=i;
}
else
if(b<arr[i])
b=arr[i];
printf("\n the second largest number is %d ",b);
}

wap to implement bisection method to find the root of (X)*log10(X)-1.2.



#define f(x) (x)*log10(x)-1.2
#include<stdio.h>
# include<math.h>
 main()
{
float i,a,b,c,t=0;
for(i=0;;i++)
{
if(f(i)>0&&f(i+1)<0)
{
a=i;b=i+1;break;}
if((f(i)<0)&&(f(i+1)>0))
{
a=i+1;b=i;break;}
}
for(i=0;;i++)
{
c=(a+b)/2;
if(f(c)>0)
a=c;
else
b=c;
if(fabs(c-t)<=.00005)
break;
t=c;
}
printf("\nthe root is %f",c);
}

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...