0% found this document useful (0 votes)
43 views19 pages

Ass 3

Uploaded by

ar22chb0a41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views19 pages

Ass 3

Uploaded by

ar22chb0a41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 14

Q1

#include <iostream>;

using namespace std;

int main()

int a[100], i, j, n, t=0, max=0, count=0;

cout<<"Enter array size ";

cin>>n;

cout<<"Enter array elements ";

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

cin>>a[i];

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

count=0;

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

if(a[j]==a[i]){

count++;

if(count>max){
max=count;

t=a[i];

cout<<t<<" is repeated "<<max<<" no. of times ";

return 0;

Q2

#include <iostream>

using namespace std;

int main()

int i, j, n, count=0, max=0, f;

int a[100], s[100];

cout<<"Enter the array size ";

cin>>n;

cout<<"Enter the array elements ";

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

cin>>a[i];
}

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

f=0;

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

f=f+a[j];

s[i]=f;

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

cout<<s[i]<<" ";

Q3)
#include<iostream>

using namespace std;

int main()

int a[10],l,b[10],i,j,k,x,y;

cout<<"enter the size of 1st and 2nd array "<<endl;

cin>>x>>y;

for(i=0;i<x;i++)
cin>>a[i];

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

cin>>b[j];

for(k=x;k<x+y;k++)

a[k] = b[k-x];

cout<<a[k];

for( int l=0;l<x+y;l++)

for(int m=0;m<x+y-1-l;m++)

if(a[m] < a[m+1])

int k=a[m];

a[m]=a[m+1];

a[m+1]=k;

for(int o=0;o<x+y;o++)

int search = a[o];

int loc = o;
for(int p=1+o;p<x+y;p++)

if(search > a[p])

search = a[p];

loc = p;

// swap(a[o],a[loc]);

swap(a[o],a[loc]);

for(int n =0;n<x+y;n++)

cout<<a[n]<<endl;

return 0;

Q 4)

#include <iostream>

using namespace std;

int main()

int a[100], k, i, t, n;
cout<<"Enter array size "<<endl;

cin>>n;

cout<<"Enter array elements ";

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

cin>>a[i];

cout<<"Enter the position of largest element ";

cin>>k;

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

if (a[j]>a[j+1])

t=a[j];

a[j]=a[j+1];

a[j+1]=t;

cout<<"The "<<k<<"th "<<"largest element is "<<a[k-1];

Q7

#include <iostream>

using namespace std;

int main()
{

int a[100][100], b[100][100], r, c, i, j;

cout<<"Enter number of rowas and columns "<<endl;

cin>>r>>c;

cout<<"Enter matrix elements ";

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

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

cin>>a[i][j];

b[j][i]=a[i][j];

if(a==b){

cout<<"The matrix is symmetric ";

else {

cout<<"The matrix is not symmetric";

return 0;

Q8

#include <iostream>
using namespace std;

int main()

int a[100][100], r, c, i, j, x;

cout<<"Enter number of rowas and columns "<<endl;

cin>>r>>c;

cout<<"Enter matrix elements ";

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

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

cin>>a[i][j];

cout<<"Enter the element to be searched ";

cin>>x;

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

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

if(a[i][j]==x){

cout<<x<<" is found at "<<i<<", "<<j;

}
}

Q9)

#include <iostream>

using namespace std;

int main()

int a[100][100], r, i, j, s=0;

cout<<"Enter number of rowas and columns "<<endl;

cin>>r;

cout<<"Enter matrix elements ";

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

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

cin>>a[i][j];

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

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

if(i==j){

s=s+a[i][j];

}
}

cout<<"The sum of principal diagonal elements of the matrix is "<<s;

10)

#include<iostream>

using namespace std;

int main()

int a[16], b[4][4], i, j, k, c;

cout<<"Enter 1D array elements"<<endl;

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

cin>>a[i];

cout<<"Converted 2D array is "<<endl;

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

for(k=0; k<4; k++)

{
c = j*4 + k;

b[j][k] = a[c];

cout<<b[j][k]<<" ";

cout<<endl;

return 0;

1)

#include<iostream>

using namespace std;

int main()

{ cout<<"22chb0a41 arif raza "<<endl;

int a[10],b,c,d,e,n,i,j,k,search;

cout<<"enter size of array"<<endl;

cin>>n;

cout<<"enter elements"<<endl;

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

cin>>a[i];

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

{ search = a[j];
d = 1;

for(k=j+1;k<n;k++)

if(search == a[k])

count++;

if(d>>e)

e = d;

b = a[j];

cout<<"element "<<b<<" is repeated "<<max<<" times"<<endl;

return 0;

11)

#include<iostream>

using namespace std;

int main() unresolved error

{ cout<<"22chb0a01 vaidikkumar"<<endl;

char a[100];
int b,c,d,e,i;

cout<<"enter string"<<endl;

cin.getline(a,100);

i = 0;

b,c,d,e = 0;

while(a[i]!='\0')

switch (a[i])

case 'A' ... 'Z' : b++;

break;

case 'a' ... 'z' : b++;

break;

case '0' ... '9' : c++;

break;

case ' ' : e++;

break;

default : d++;

i++;

}
cout<<"number of alphabets in string = "<<b<<endl;

cout<<"number of digits in string = "<<c<<endl;

cout<<"number of special characters = "<<d<<endl;

return 0;

6)

#include<iostream>

using namespace std;

int main()

int a[10][10],i,j,n,k,l,m,o,p,q,sum_r,sum_c;

cout<<"enter n"<<endl;

cin>>n;

cout<<"enter array elements"<<endl;

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

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

cin>>a[i][j];

cout<<endl;

cout<<"required martix"<<endl;

for(k=0;k<n;k++)
{

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

cout<<a[k][l]<<" ";

cout<<endl;

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

{ sum_r = 0;

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

sum_r = sum_r + a[m][o];

cout<<"sum of elements in row "<<m+1<<" = "<<sum_r<<endl;

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

{ sum_c = 0;

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

sum_c = sum_c + a[q][p];

cout<<"sum of elements in column "<<p+1<<" = "<<sum_c<<endl;

return 0;

}
Q13)

#include <iostream>

#include <cstring>

using namespace std;

int main()

int l;

cout<<"Enter the number of words::";

cin>>l;

char c[100][100];

for(int i=0;i<l;i++)

cin>>c[i];

// for(int i=0;i<l;i++)

// cout<<c[i]<<endl;

char t[100];

for(int i=0;i<l;i++)

for(int j=0;j<l-1;j++)

if(strcmp(c[j],c[j+1])>0)

strcpy(t,c[j]);
strcpy(c[j],c[j+1]);

strcpy(c[j+1],t);

cout<<"Sorted names::"<<endl;

for(int i=0;i<l;i++)

cout<<c[i]<<" ";

14)

#include<iostream>

using namespace std;

int main()

{ cout<<"22chb0a41 arif raza "<<endl;

char s[100];

int a,i,j;

a = 0;

cout<<"enter string"<<endl;

cin.getline(s,100);

for(j=1;s[j]!='\0';j++);

for(i=0;i<=j/2;i++)
{

if(s[i]!=s[j-i-1])

a++;

if(a==0)

cout<<"given string is palindrome"<<endl;

else

cout<<"given string is not a palindrome"<<endl;

return 0;

You might also like