Ajit Pant MSM Enrollment No 18312004 Batch S2
Ajit Pant MSM Enrollment No 18312004 Batch S2
int main()
{
int arr[SIZE] = {12, 34, 45, 9, 8, 90, 3};
int n= sizeof(arr)/sizeof(arr[0]);
int i = 0;
int o[SIZE],e[SIZE];
int oi=0,ei=0;
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
e[ei]=arr[i];
ei++;
}
else
{
o[oi]=arr[i];
oi++;
}
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
}
cout<<”Even \n";
for(int i=0;i<ei;i++)
cout<<e[i]<<endl;
cout<<”Odd \n";
for(int i=0;i<oi;i++)
cout<<o[i]<<endl;
return 0;
}
Output:
Even
12
34
8
90
Odd
45
9
3
{
for (int i = 0; i < n; ++i)
cout << array[i] << " " << flush;
cout << endl;
}
while (swapped)
{
swapped = false;
j++;
for (int i = 0; i < n - j; ++i)
{
if (array[i] < array[i + 1])
{
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
swapped = true;
}
}
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
}
}
int main() {
int array[] = {94, 42, 50, 95, 333, 65, 54, 456, 1, 1234};
int n = sizeof(array)/sizeof(array[0]);
descendingSort(array, n);
}
cout << endl;
}
}
cout<<endl;5l
}
cout << endl;
}
void AddMatrices (int myarray1[SIZE][SIZE], int myarray2[SIZE][SIZE] ,int
result[SIZE][SIZE])
{
for (int i = 0; i < SIZE ; i++)
{
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
return;
}
int main ()
{
int x [SIZE][SIZE];
int y [SIZE][SIZE];
int r[SIZE][SIZE];
cout<<”Enter First matrix\n";
ReadMatrix(x);
cout<<”Enter Second matrix\n";
ReadMatrix(y);
AddMatrices (x,y,r);
cout<<”Addition of the matrices\n";
ShowMatrix(r);
MultMatrices(x,y,r);
cout<<”Multiplication of the matrices\n";
ShowMatrix(r);
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
}
Output:
Enter First matrix
12
12
Enter Second Matrix
13
13
Addition of the matrices
25
25
Multiplication of the matrices
39
39
5. Write a code in C++, to read a square matrix and to rotate the square matrix
in ' clockwise manner by 90 degrees.
Answer
#include<iostream>
#define n 2
using namespace std;
int main()
{
int mat[n][n];
for (int i=0;i<n;i++)
for(int j=0;j<n;j++)
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
cin>>mat[i][j];
int rot[n][n];
cout<<”Rotated"<<endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
rot[i][j]=mat[n-1-j][i];
cout<<rot[i][j]<<” “;
}
cout<<endl;
}
return 0;
}
Output:
12
34
Rotated
31
42
6. Write a program in C++ that uses/ describe the following: getchar( ).
putchar( ), puts, gets, difference between cunt and puts difference between
cin and gets, get ( ), put( ), getline( ) and write( ).
#include<iostream>
#include<studio.h>
#include<string>
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
}
Output
Enter text
C
C
E
E
Hello
Hello
Hi Sir
Hi Sir
7. Write programs in C++ that uses/ describe the functions involved in “string”.
Answer
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
#include <iostream>
#include<string.h>
using namespace std;
return true;
}
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
int main()
{
string fnum = "23.342";
cout << "Floating part is : " << returnFloatingPart(fnum) << endl;
return 0;
}
AJIT PANT MSM ENROLLMENT NO 18312004 BATCH S2
Output
Floating part is : 342
string contains only digit
google%20com%20in