0% found this document useful (0 votes)
119 views14 pages

Write A Programme To Find The Transpose of A Two Dimensional Matrix

The document contains 7 code snippets in C programming language. Each snippet demonstrates how to write code for a different task such as finding the transpose of a matrix, calculating the factorial of a number, checking if a string is a palindrome, finding the largest number in an array, sorting student data by marks using structures, printing a diamond pattern of asterisks given a number, and removing duplicate elements from a vector. The output generated by running each code snippet is also included.

Uploaded by

arunvkumar7
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views14 pages

Write A Programme To Find The Transpose of A Two Dimensional Matrix

The document contains 7 code snippets in C programming language. Each snippet demonstrates how to write code for a different task such as finding the transpose of a matrix, calculating the factorial of a number, checking if a string is a palindrome, finding the largest number in an array, sorting student data by marks using structures, printing a diamond pattern of asterisks given a number, and removing duplicate elements from a vector. The output generated by running each code snippet is also included.

Uploaded by

arunvkumar7
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 14

1

1. Write a programme to find the transpose of a two dimensional matrix…


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20][20],b[20][20],m,n;
cout<<"enter the no. of rows and colums:\n";
cin>>m>>n;
cout<<"enter the matrix:\n";
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
cout<<"the entered matrix is:\n";
for(i=0;i<m;i++)
{
for(int j=0;j<n;j++)
cout<<a[i][j]<<"\t";
cout<<"\n";
}
for(int k=0;k<m;k++)
for(int l=0;l<n;l++)
b[l][k]=a[k][l];
cout<<"the transposed matrix is:\n";
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<b[i][j]<<"\t";
cout<<"\n";
}
getch();
return;
}
Output:
enter the no. of rows and colums:
3
4
2

enter the matrix:


1
2
3
4
5
6
7
8
9
10
11
12
the entered matrix is:
1 2 3 4
5 6 7 8
9 10 11 12
the transposed matrix is:
1 5 9
2 6 10
3 7 11
4 8 12

2.write a programme to find the factorial of a number….


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,f=1,y;
cout<<"enter the no. whose factorial is to be found:";
cin>>x;
y=x;
while(y!=0)
{
f=f*y;
y--;
3

}
cout<<"\nfactorial of "<<x<<" is:"<<f;
getch();
return;
}
Output:
enter the no. whose factorial is to be found:6
factorial of 6 is:720

3.Write a programme to check whether given string is a palindrome….


#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char s[100];
int l;
cout<<"enter the string:\n";
cin>>s;
l=strlen(s);
for(int i=0;i<=l/2;i++)
if(s[i]!=s[l-i-1])
{
cout<<"it is not a palindrome";
getch();
return;
}
cout<<"it is a palindrome";
getch();
return;
}
Output:
case-1
enter the string:
asddsa
it is a palindrome
4

case 2
enter the string:
asdfghhkltrjyj
it is not a palindrome

4.Write a programme to the largest among an array of numbers….


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[100],l,n;
cout<<"enter the limit:";
cin>>n;
cout<<"enter the array:\n";
for(int i=0;i<n;i++)
cin>>a[i];
l=a[0];
for(i=1;i<n;i++)
if(l<a[i])
l=a[i];
cout<<"the largest no. is:"<<l;
getch();
return;
}
Output:
enter the limit:8
enter the array:
8
1
7
9
4
6
3
2
the largest no. is:9
5

5.Write a programme to input name,age and marks of five subjects of ten


students and sort them according to marks using structures…
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stdnt
{
char name[50];
int age,mark[5],t;
};
void main()
{
clrscr();
stdnt a[10];
int s;
cout<<"enter the details.......\n";
for(int i=0;i<10;i++)
{
a[i].t=0;
cout<<"\n\ndetails of student "<<i+1<<"\nenter the name:";
gets(a[i].name);
cout<<"enter age:";
cin>>a[i].age;
cout<<"enter the marks:\n";
for(int j=0;j<5;j++)
{
cout<<"subject "<<j+1<<":";
cin>>a[i].mark[j];
a[i].t+=a[i].mark[j];
}
}
for(i=0;i<9;i++)
for(int j=i+1;j<10;j++)
if(a[i].t<a[j].t)
{
s=a[i];
a[i]=a[j];
6

a[j]=s;
}
cout<<"\n\ndetails of the students in sorted form is....\n\n";
for(i=0;i<10;i++)
{
cout<<"name:"<<a[i].name;
cout<<"\nage:"<<a[i].age;
for(int j=0;j<5;j++)
cout<<"\nsubject "<<j+1<<":"<<a[i].mark[j];
cout<<"\ntotal mark:"<<a[i].t<<"\n\n";
}
getch();
return;
}
Output:
enter the details.......

details of student 1
enter the name:st1
enter age:17
enter the marks:
subject 1:45
subject 2:75
subject 3:86
subject 4:76
subject 5:61

details of student 2
enter the name:st2
enter age:17
enter the marks:
subject 1:56
subject 2:68
subject 3:67
subject 4:61
subject 5:78
7

details of student 3
enter the name:st3
enter age:18
enter the marks:
subject 1:78
subject 2:98
subject 3:89
subject 4:44
subject 5:46

details of student 4
enter the name:st4
enter age:19
enter the marks:
subject 1:98
subject 2:99
subject 3:97
subject 4:96
subject 5:95

details of student 5
enter the name:st5
enter age:17
enter the marks:
subject 1:54
subject 2:45
subject 3:51
subject 4:54
subject 5:50

details of student 6
enter the name:st6
enter age:18
enter the marks:
subject 1:74
subject 2:73
8

subject 3:72
subject 4:71
subject 5:69

details of student 7
enter the name:st7
enter age:17
enter the marks:
subject 1:97
subject 2:45
subject 3:68
subject 4:70
subject 5:80

details of student 8
enter the name:st8
enter age:19
enter the marks:
subject 1:55
subject 2:65
subject 3:67
subject 4:88
subject 5:81

details of student 9
enter the name:st9
enter age:18
enter the marks:
subject 1:81
subject 2:84
subject 3:87
subject 4:85
subject 5:40

details of student 10
enter the name:st10
enter age:17
9

enter the marks:


subject 1:78
subject 2:65
subject 3:70
subject 4:60
subject 5:90

details of the students in sorted form is....

name:st4
age:19
subject 1:98
subject 2:99
subject 3:97
subject 4:96
subject 5:95
total mark:485

name:st9
age:18
subject 1:81
subject 2:84
subject 3:87
subject 4:85
subject 5:40
total mark:377

name:st7
age:17
subject 1:97
subject 2:45
subject 3:68
subject 4:70
subject 5:80
total mark:360

name:st10
10

age:17
subject 1:78
subject 2:65
subject 3:70
subject 4:60
subject 5:90
total mark:363

name:st6
age:18
subject 1:74
subject 2:73
subject 3:72
subject 4:71
subject 5:69
total mark:359

name:st8
age:19
subject 1:55
subject 2:65
subject 3:67
subject 4:88
subject 5:81
total mark:356

name:st3
age:18
subject 1:78
subject 2:98
subject 3:89
subject 4:44
subject 5:46
total mark:355

name:st1
age:17
11

subject 1:45
subject 2:75
subject 3:86
subject 4:76
subject 5:61
total mark:343

name:st2
age:17
subject 1:56
subject 2:68
subject 3:67
subject 4:61
subject 5:78
total mark:330

name:st5
age:17
subject 1:54
subject 2:45
subject 3:51
subject 4:54
subject 5:50
total mark:254

6.Write a programme that reads a positive integer n and then prints a


dimond of asterisks(*) in 2n-1 rows. For example if n is 4, the output would
be….
*
***
*****
*******
*****
***
*
12

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n;
cout<<"enter the value of n:";
cin>>n;
cout<<"the reduired dimond is\n\n";

for(int i=1;i<=n;i++)
{
for(int j=0;j<n-i;j++)
cout<<" ";
for(j=1;j<2*i;j++)
cout<<"*";
cout<<"\n";
}
i--;
for(i=n-1;i>0;i--)
{
for(int j=0;j<n-i;j++)
cout<<" ";
for(j=1;j<2*i;j++)
cout<<"*";
cout<<"\n";
}
getch();
return;
}
13

Output:
*
***
*****
*******
*********
***********
*************
***************
*************
***********
*********
*******
*****
***
*
7.Write a programme to delete duplicates in a given vector and print
resultant vector…
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a[100],n;
cout<<"enter the limit:";
cin>>n;
cout<<"enter the array:\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(a[i]==a[j])
{
for(int k=j;k<n-1;k++)
a[k]=a[k+1];
n--;
14

}
cout<<"the resultant array is:\n";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
return;
}

Output:
enter the limit:10
enter the array:
7
6
8
5
7
9
4
3
9
1
the resultant array is:
7 6 8 5 9 4 3 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy