#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
cout<<"Enter the numbers:"<>arr[i];
}
cout<<"The negative elements in the array = "<
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int sum=0;
cout<<"Enter the numbers:"<>arr[i];
sum=sum+arr[i];
}
cout<<"The sum of all the elements in the array = "<
#include
using namespace std;
int main()
{
const int size=4;
int arr[size];
int max;
int min;
cout<<"Enter the numbers:"<>arr[i];
}
max=arr[0];
min=arr[0];
for(int i=0;iarr[i])
{
min=arr[i];
}
}
cout<<"The maximum between these numbers = "<
Write a C++ program to find the Second largest element in the array.
#include
#include
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int firstMax;
int secondMax;
int x=time(0);
srand(x);
for(int i=0;i
Write a c++ program to insert the element in the end of the array.
#include
#include
#include
using namespace std;
int main()
{
const int size=11;
int arr[size];
int num;
int x=time(0);
srand(x);
for(int i=0;i<10;i++){
arr[i]=(rand()%10)+1;
}
for(int i=0;i<10;i++){
cout<>num;
for(int i=0;i
Write a c++ program to insert the element at the specific position.
#include
#include
#include
using namespace std;
int main()
{
const int size=11;
int arr[size];
int num;
int pos;
int x=time(0);
srand(x);
for(int i=0;i<10;i++){
arr[i]=(rand()%10)+1;
}
for(int i=0;i<10;i++){
cout<>num;
cout<<"Enter the specific position that you want to insert :"<>pos;
for(int i=size;i>pos-2;i--){
arr[i]=arr[i-1];
if(i==pos-1)
{
arr[i]=num;
}
}
cout<<"The inserted array at the specific position = "<
Write a c++ program to delete the element at the specific position.
#include
#include
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int num;
int pos;
int x=time(0);
srand(x);
for(int i=0;i>pos;
for(int i=pos-1;i
Write a C++ Program to count the frequncy of the elements in the array.
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int freq[size]={0};//Initailize the whole array of frequency with zero
int count;
cout<<"Enter the elements of the array :"<>arr[i];
}
cout<<"The elements that you want to be enter = "<
Write a C++ program print all unique elements in the array.
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int freq[size]={0};//Initailize the whole array of frequency with zero
int count;
cout<<"Enter the elements of the array :"<>arr[i];
}
cout<<"The elements that you want to be enter = "<
Write a C++ program to count number of duplicate elements in the array.
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int freq[size]={0};//Initailize the whole array of frequency with zero
int count;
cout<<"Enter the elements of the array :"<>arr[i];
}
cout<<"The elements that you want to be enter = "<
Write a c++ progarm to copy the one array into the another array.
#include
#include
#include
using namespace std;
int main()
{
const int size=10;
int arr[size];
int copy[size]={0};
int x=time(0);
srand(x);
for(int i=0;i
Write a C++ program to delete all the duplicate elements in the array:
#include
using namespace std;
int main()
{
int size = 10;
int arr[size] = {};
cout << "Enter the elemnts in the array:" << endl;
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
for (int i = 0; i < size; i++)
{ // outer loop i can control the index that can be compared to be repeated or not
for (int j = i + 1; j <= size; j++)
{ // innner loop j can be control the index with the i index can be compared
if (arr[i] == arr[j])
{
for (int k = j; k <= size; k++)
{ // most inner loop k can shift the array to overwrite the repeated index with the next index element
arr[k] = arr[k + 1]; // when we can shift the array the size of array after one iteration of k became size-1
}
size--; // so write as size-- after the shifting of an full array
}
}
}
cout << "The latest array is here:" << endl;
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
return 0;
}
Write a C++ program to merge two arrays into the second array:
#include
using namespace std;
int main()
{
int size1;
int size2;
int size3;
cout<<"Enter the size of the first array:"<>size1;
int arr1[size1];
cout<<"Enter the elements of one array:"<>arr1[i];
}
cout<<"Enter the size of the first array:"<>size2;
int arr2[size2];
cout<<"Enter the elements in the second array:"<>arr2[i];
}
size3=size1+size2;
int arr3[size3]={};
cout<<"The third array before the merging is initialized to zero as:"<
Write a C++ program to revers the array:
#include
#include
#include
using namespace std;
int main()
{
const int size=10;
int x=time(0);
srand(x);
int arr[size];
cout<<"The array without reversed as:"<
Write a C++ program to put the even and odd elements of an array into the two separate arrays:
#include
using namespace std;
int main()
{
const int size=10;
int arr3[size];
int arr_even[size]={};
int arr_odd[size]={};
int even=0;
int odd=0;
cout<<"Enter the elements in the array:"<>arr3[i];
}
cout<<"The elements enter in the array are :"<
Sorting Alhorithms:
Bubble Sort
#include
#include
#include
using namespace std;
int main()
{
int x = time(0);
srand(x);
int size = 10;
int arr[size];
cout << "The elemnets in the array are given as:" << endl;
for (int i = 0; i < size; i++)
{
// arr[i] = (rand() % 20) + 1;
cin>>arr[i];
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
cout << endl;
int innerSize=size;
cout << "The sorted array in the asscending order is given as as:" << endl;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < innerSize; j++)
{
int temp = arr[j + 1];
if (arr[j] > arr[j + 1])
{
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
innerSize--;
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
cout << endl;
// cout << sizeof(arr) / sizeof(int); // To check the size of the array that can be given in the array:
return 0;
}
Selection Sort
#include
#include
#include
using namespace std;
int main()
{
int size = 10;
int x = time(0);
srand(x);
int arr[size] = {};
int min_index;
for (int i = 0; i < size; i++)
{
arr[i] = (rand() % 20) + 1;
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
for (int i = 0; i < size - 1; i++)
{
min_index = i;
for (int j = i + 1; j < size; j++)
{
if (arr[j] < arr[min_index])
{
min_index = j;
}
}
int temp;
temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
cout << endl;
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
return 0;
}
Insertion Sort
#include
#include
#include
using namespace std;
int main()
{
int x = time(0);
srand(x);
const int size = 10;
int arr[size];
for (int i = 0; i < size; i++)
{
arr[i] = (rand() % 10) + 1;
}
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
for (int i = 1; i < size; i++)
{
int temp;
if (arr[i] < arr[i - 1])
{
temp = arr[i];
int j = i;
do
{
arr[j] = arr[j - 1];
j--;
} while (j > 0 && arr[j - 1] > temp);
arr[j] = temp;
}
}
cout << endl;
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
return 0;
}
>2D-Arrays
Write a program to add two matrixes.
#include
#include
#include
#include
using namespace std;
int main()
{
int x=time(0);
srand(x);
const int row=5;
const int col=4;
int arr2d[row][col];
int arr2d1[row][col];
int sum[row][col];
int sum1;
for(int i=0;i
Write a C++ program to find the daigonal sum of the matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=4;
const int col=5;
int sum=0;
int board[row][col];
for(int i=0;i
Write a C++ Program to find the determinent of a 3x3 by matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
int x=time(0);
srand(x);
int deter=0;
int a,b,c;
int board[row][col];
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ program for the diagonal interchange.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=5;
const int col=5;
int board[row][col];
for(int i=0;i=0;i++,j--)
{
int temp;
temp=board[i][i];
board[i][i]=board[i][j];
board[i][j]=temp;
}
cout<
Write a C++ progarm to find the given matrix is equal matrix or not
#include
#include
using namespace std;
int main()
{
int r1,c1,r2,c2;
bool flag=true;
cout<<"Enter the row of board 1:"<>r1;
cout<<"Enter the column of board 1:"<>c1;
cout<<"Enter the row of board 2:"<>r2;
cout<<"Enter the column of board 2:"<>c2;
int board1[r1][c1];
int board2[r2][c2];
cout<<"Enter the board 1:"<>board1[i][j];
}
}
cout<<"Enter the board 2:"<>board2[i][j];
}
}
cout<<"board 1 is as:"<
Write a C++ program to check the given matrix is identity matrix or not.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
int x=time(0);
srand(x);
bool flag =true;
int board[row][col];
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ progarm to check given matrix is lower traingular matrix or not.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
bool flag=true;
int board[row][col];
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ Progarm to find out the minor diagonal sum of the matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
int sum=0;
int board[row][col];
for(int i=0;i=0 && j
Write a C++ program to Multiply two matrixes.
#include
#include
#include
#include
using namespace std;
int main()
{
int x=time(0);
srand(x);
int r1,c1;
int r2,c2;
int multi1,multi2;
cout<<"Enter the number of rows of first board:"<>r1;
cout<<"Enter the number of columns of first board:"<>c1;
cout<<"Enter the number of rows of secind board:"<>r2;
cout<<"Enter the number of columns of secind board:"<>c2;
/*It is must that the number of columns of first board
is equal to the number of rows of second board*/
while(c1!=r2)
{
cout<<"Invalid input!"<>r1;
cout<<"Enter the number of columns of first board:"<>c1;
cout<<"Enter the number of rows of secind board:"<>r2;
cout<<"Enter the number of columns of secind board:"<>c2;
}
int board1[r1][c1];
int board2[r2][c2];
/*Resultant board has number of rows equal to the board_1 rows
And number of columns equal to the board_2 columns*/
int multi[r1][c2]={0};
//Input for the board 1
for(int i=0;i>board1[i][j];
}
}
//Display board 1
//Display
cout<<"board 1 :"<>board2[i][j];
}
}
//Display board 2
cout<<"board 2:"<
Write a C++ Program to check the given marix is scalar or not.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row = 5;
const int col = 5;
int arr[row][col];
int num;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
arr[i][j] = rand() % 9;
}
}
cout << "The board is given as:" << endl;
for (int i = 0; i < row; i++)
{
cout << left;
for (int j = 0; j < col; j++)
{
cout << setw(5) << arr[i][j];
}
cout << endl;
}
cout << endl;
cout << "Enter the number that you want to multiplay:" << endl;
cin >> num;
cout << endl;
for (int i = 0; i < row; i++)
{
cout << left;
for (int j = 0; j < col; j++)
{
cout << setw(5) << (num * arr[i][j]);
}
cout << endl;
}
return 0;
}
Write a C++ program to check whether the given matrix is upper traingular matrix or not.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
bool flag=true;
int board[row][col];
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ program to find the transpose of a matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=4;
const int col=6;
int board[row][col];
int sum=0;
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ program to find the sum of the upper traingular matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
int board[row][col];
int sum=0;
for(int i=0;i>board[i][j];
}
}
for(int i=0;i
Write a C++ program to find the sum of the lower traingular matrix.
#include
#include
#include
#include
using namespace std;
int main()
{
const int row=3;
const int col=3;
int board[row][col];
int sum=0;
for(int i=0;i>board[i][j];
}
}
for(int i=0;i=0;j--)
{
sum+=board[i][j];
}
}
cout<
3D-Arrays
Initalization and printing
#include
#include
#include
#include
using namespace std;
int main()
{
int x=time(0);
srand(x);
const int row=10;
const int col=10;
const int z=10;
int three_D[row][col][z];
//input
for(int k=0;k>three_D[i][j][k];
}
}
}
//output
for(int k=0;k
Character Arrays
Wrire a C++ Program to find the Vowels,Cononants,Symbols ,numbers in the array.
#include
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
cin.getline(ch,size);
int alphabtes;
int symboles;
int numbers;
int vowels;
int consonants;
for(int i=0;ch[i]!='\0';i++)
{
if((ch[i]>='a' && ch[i]<='z') ||(ch[i]>='A'&&ch[i]<='Z'))
{
alphabtes++;
}
else if(ch[i]>='0' && ch[i]<='9')
{
numbers++;
}
else
{
symboles++;
}
if(ch[i]=='a'|| ch[i]=='i'||ch[i]=='e'||ch[i]=='o'||ch[i]=='u')
{
vowels++;
}
else
{
consonants++;
}
}
cout<
Write a C++ program in character array to find out which charracter string is greater(Comparing of two
strings).
#include
#include
using namespace std;
int main()
{
//it is basically works on the ascii values
int size=100;
char ch1[size];
char ch2[size];
int result;
cin.getline(ch1,size);
cin.getline(ch2,size);
result= strcmp(ch1,ch2);
switch(result)
{
case -1:
{
cout<
Concatination of two character strings
#include
#include
using namespace std;
int main()
{
int size=100;
char ch1[size];
char ch2[size];
cin.getline(ch1,size);
cin.getline(ch2,size);
strcat(ch1,ch2);
strncat(ch1,ch2,5);
strcat(ch1,"Muhib");
cout<
C++ progarm to copy one character string into another (methods)
#include
#include
using namespace std;
int main()
{
int size=100;
char arr1[size];
char arr2[size];
cin.getline(arr1,size);
cin.getline(arr2,size);
strcpy(arr1,arr2);
strncpy(arr1,arr2,5);
strcpy(arr1,"Muhib Arshad");
cout<
#include
using namespace std;
int main()
{
int size=100;
char arr1[size];
char arr2[size];
cin.getline(arr1,size);
cin.getline(arr2,size);
for(int i=0;arr2[i]!='\0';i++)
{
arr1[i]=arr2[i];
}
cout<
Write a C++ progarm to find out how many times the given word is repeated in the character string.
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
char se;
int count=0;
cin.getline(ch,size);
cout<<"Enter the count character :"<>se;
for(int i=0;ch[i]!='\0';i++)
{
if(ch[i]==se)
{
count++;
}
}
cout<
Write a C++ program to find index at which the first occurance of a letter in a string
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
char se;
int index;
cin.getline(ch,size);
cout<<"Enter the first occurance character :"<>se;
bool flag =false;
for(int i=0;ch[i]!='\0' && flag==true;i++)
{
if(ch[i]==se)
{
index=i;
flag=true;
}
}
cout<<"The character "<
Write a C++ program to find the occurance of each letter in a sentence.
#include
using namespace std;
int main()
{
const int size=100;
char ch[size];
int arr[size]={0};
int count=0;
int index=0;
int max;
cout<<"Eneter the character string:"<
Write a C++ prorgram to find the highest frequency of a letter in a character string.
#include
using namespace std;
int main()
{
const int size=100;
char ch[size];
int arr[size]={0};
int count=0;
int index=0;
int max;
cout<<"Eneter the character string:"<max)
{
max=arr[i];
index=i;
}
}
cout<<"The highest frequency of the character in the string is "<
Write a C++ program to find the at which last index the given letter exist in a character string.
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
char se;
int index;
cin.getline(ch,size);
cout<<"Enter the occurance character :"<>se;
cout<<"The character "<
Write a C++ program to remove the given letter at ist last occurance in a character string.
#include
using namespace std;
int main()
{
int size = 100;
char ch[size];
char toremove;
cin.getline(ch, size);
for (int i = 0; ch[i] != '\0'; i++)
{
if (isupper(ch[i]))
{
ch[i] = tolower(ch[i]);
}
}
int index = 0;
cout << "Enter the character that you want to remove its first occurance:" << endl; cin>
> toremove;
toremove = tolower(toremove);
cin.ignore();
for (int i = 0; ch[i] != '\0'; i++)
{
if (ch[i] == toremove)
{
index = i;
}
}
for (int j = index; ch[j + 1] != '\0'; j++)
{
ch[j] = ch[j + 1];
}
for (int i = 0; ch[i + 1] != '\0'; i++)
{
cout << ch[i]; } return 0; }
Write a C++ program to find the length of a string.
#include
using namespace std;
int main()
{
int size;
cin>>size;
cin.ignore();
char ch[size];
cin.getline(ch,size);
int count=0;
for(int i=0;ch[i]!='\0';i++){
count++;
}
cout<
Write a C++ program to convert the all lowerCase letters to Uppercase letters.
#include
#include
using namespace std;
int main()
{
//it is basically works on the ascii values
int size=100;
char ch1[size];
cin.getline(ch1,size);
for(int i=0;i
Write a C++ program to find the lowest occurance of a letter in a character string.
#include
using namespace std;
int main()
{
const int size=100;
char ch[size];
int arr[size]={0};
int count=0;
int index=0;
int min;
int lowest[size]={};
cout<<"Eneter the character string:"<
Write a C++ program to find out given word is palindrome or not.
#include
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
cin.getline(ch,size);
int length=strlen(ch)-1;
bool flag =true;
int k=0;
while(ch[k]!='\0')
{
ch[k]=tolower(ch[k]);
k++;
}
for(int i=0,j=length;ch[i]!='\0';i++,j--)
{
if(ch[i]!=ch[j])
{
flag=false;
}
}
if(flag==false)
{
cout<<"It is not a palindrome!"<
Write a C++ program to remove the fist occurance of a letter at index.
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
char toremove;
cin.getline(ch,size);
for(int i=0;ch[i]!='\0';i++)
{
if(isupper(ch[i]))
{
ch[i]=tolower(ch[i]);
}
}
bool flag=false;
cout<<"Enter the character that you want to remove its first occurance:"<
>toremove;
toremove=tolower(toremove);
cin.ignore();
for(int i=0;(ch[i]!='\0') && flag==false;i++)
{
if(ch[i]==toremove)
{
for(int j=i;ch[j+1]!='\0';j++)
{
ch[j]=ch[j+1];
}
flag=true;
}
}
for(int i=0;ch[i+1]!='\0';i++)
{
cout<
Write a C++ program to reverse the given character string.
#include
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
char reverse[size];
int x;
cin.getline(ch,size);
x=strlen(ch);
int i=0,j=x-1;
while(ch[i]!='\0')
{
reverse[i]=ch[j];
i++;
j--;
}
cout<
Write a C++ program to convert all the letters of the character string into the toggle case.
#include
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
int count=0;
cin.getline(ch,size);
for(int i=0;ch[i]!='\0';i++)
{
if(islower(ch[i]))
{
ch[i]=toupper(ch[i]);
}
else if(isupper(ch[i]))
{
ch[i]=tolower(ch[i]);
}
}
cout<
Write a C++ program to find the total letters in the character string.
#include
#include
using namespace std;
int main()
{
int size=100;
char ch[size];
cin.getline(ch,size);
int count=0;
for(int i=0;ch[i]!='\0';i++)
{
if(ch[i]==' ')
{
count++;
}
}
cout<
Write a C++ Program to revres the words in the string.
#include
#include
using namespace std;
int main()
{
int size = 100;
char ch[size];
char reverse[size];
int x;
int length;
cin.getline(ch, size);
x = strlen(ch);
length = x - 1;//get lenghth without null character
int z = 0;//index of reverse array
int i = 0, j = length;//j backward jany ka ly
while (ch[i] != ch[x])//jab tak last index of array nhi ajata
{
if (ch[j] == ' ' || ch[j] == ch[0])//agr j barabar space ka or ya j barabar hai first
index ka
{
if (ch[j] != ch[0])//agr ch[j] first index ka barabr nhi hai
{
int k = j + 1;//new variable k takh space sa agy ka indexs ko revers array ma copy
karwa saky ,+1 is ley takh space sa agy sa start ho
while (ch[k] != ' ' && ch[k] != '\0')//ch[k] agr space nhi or ch[k] null akhri wala
bhi nhi hai
{
//kia kary
reverse[z] = ch[k];//reverse array ka first to onward indexes ma wo ch[k] ko copy
karta jay
k++;//k ko agy next index pa la jay
z++;// reverse array ka index ko bhi next move kary
if (ch[k] == ' ' || ch[k] == '\0')//ch[k] agr space hai or ch[k] null akhri wala bhi
nhi hai to
{
reverse[z] = ' ';//reverse ka z index ko space assign kar de
z++;//reverse array index ++ ho jay takh usma space na ay
}
}
}
if (ch[j] == ch[0])//agr ch[j] first index hai
{
int m=z;
int l=0;
while(ch[l]!=' '){
reverse[z] = ch[l];//reverse z ko ch[0] kar de
m++;
z++;
l++;
}
}
}
i++, j--;//ch indexes ko move kary sath hi j akhri index ko bacward bhi chalay
}
reverse[x] = '\0';//jasy hi loop ruky reverse ka x last index ko null kar de takh
array stop ho jay
cout << reverse; return 0; }
Whats make this website differents from others?
Amazing Feature That Increase your Productivity
If you don't find any problem,in this website and if you have a very difficult assignment
question that
is not present on internet ,then you dont bother yourself,we are here to solve every problem
of
your
life you just click on the Problem asking button and write your problem we slove the code of
your
problem and sent you on your email addres that you put in the sin up form.