Professional Documents
Culture Documents
1. Rotation of matrix
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[10][10];
int row, column, flag;
cin >> row;
cin >> column;
for(int i = 0; i < column; i++){
for(int j = 0; j < row; j++){
cin >> arr[i][j];
}
}
cout << "Enter flag: ";
cin >> flag;
int *p;
return 0;
}
2.
Swap coresponding elements of aray.
Traversing the array and swapping i and i + 1 element.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, *p;
//Input size of array
cin >> n;
int arr[n];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
//p gets the pointer to array after swapping
p = swapArr(arr, n);
cout << endl;
for(int i = 0; i < n; i++){
cout << *(arr + i) << " ";
}
cout << endl;
return 0;
}
3. Removing vowels from a string
#include<iostream>
using namespace std;
int main(){
string s, res = "";
cout << "Enter string: ";
//cin.ignore();
cin >> s;
for(int i = 0; i < s.length(); i++){
char c = s[i];
switch(c){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
break;
default:
res += s[i];
}
}
cout << "String = " + res << endl;
}
4. Print the Pattern
1
11
121
1331
14641
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
//Input number of rows
cin >> x;
printPascal(x);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
void squarePatternPrint(int n){
int p = n;
for(int i = 1; i <= n; i += 2){
int k = (i - 1) * n + 1;
for(int j = 0; j < n - 1; j++){
cout << k << "*";
k++;
}
cout << k;
cout << endl;
}
if(n % 2 != 0){
p = n - 1;
}
for(int i = p; i > 0; i -= 2){
int k = (i - 1) * n + 1;
for(int j = 0;j < n - 1; j++){
cout << k << "*";
k++;
}
cout << k;
cout << endl;
}
}
int main(){
int x;
cin >> x;
squarePatternPrint(x);
return 0;
}
6. Print the Pattern
Input
n=6
Output
1111112
3222222
3333334
5444444
5555556
7666666
#include <bits/stdc++.h>
using namespace std;
void patternprint(int);
int main(){
int num;
cin>>num;
patternprint(num);
return 0;
}
int main(){
int x;
//Input number of rows
cin >> x;
printPattern(x);
return 0;
}
***********
*********
*******
*****
***
*
#include<iostream>
#include<map>
using namespace std;
#include<iostream>
using namespace std;
int main(){
int x = 3;
printPattern(x);
return 0;
}
int main(){
int x;
//Input number of rows
cin >> x;
printPattern(x);
return 0;
}
int main(){
int x;
//Input number of rows
cin >> x;
printPattern(x);
}