Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR : Making a new C++ folder with rules #63

Merged
merged 22 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
106 changes: 53 additions & 53 deletions check_star_graph.cpp → C++ Problem/Arrays/check_star_graph.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
// CPP to find whether given graph is star or not
#include<bits/stdc++.h>
using namespace std;
// define the size of incidence matrix
#define size 4
// function to find star graph
bool checkStar(int mat[][size])
{
// initialize number of vertex
// with deg 1 and n-1
int vertexD1 = 0, vertexDn_1 = 0;
// check for S1
if (size == 1)
return (mat[0][0] == 0);
// check for S2
if (size == 2)
return (mat[0][0] == 0 && mat[0][1] == 1 &&
mat[1][0] == 1 && mat[1][1] == 0 );
// check for Sn (n>2)
for (int i = 0; i < size; i++)
{
int degreeI = 0;
for (int j = 0; j < size; j++)
if (mat[i][j])
degreeI++;
if (degreeI == 1)
vertexD1++;
else if (degreeI == size-1)
vertexDn_1++;
}
return (vertexD1 == (size-1) &&
vertexDn_1 == 1);
}
// driver code
int main()
{
int mat[size][size] = { {0, 1, 1, 1},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0}};
checkStar(mat) ? cout << "Star Graph" :
cout << "Not a Star Graph";
return 0;
}
// CPP to find whether given graph is star or not
#include<bits/stdc++.h>
using namespace std;

// define the size of incidence matrix
#define size 4

// function to find star graph
bool checkStar(int mat[][size])
{
// initialize number of vertex
// with deg 1 and n-1
int vertexD1 = 0, vertexDn_1 = 0;

// check for S1
if (size == 1)
return (mat[0][0] == 0);

// check for S2
if (size == 2)
return (mat[0][0] == 0 && mat[0][1] == 1 &&
mat[1][0] == 1 && mat[1][1] == 0 );

// check for Sn (n>2)
for (int i = 0; i < size; i++)
{
int degreeI = 0;
for (int j = 0; j < size; j++)
if (mat[i][j])
degreeI++;

if (degreeI == 1)
vertexD1++;
else if (degreeI == size-1)
vertexDn_1++;
}

return (vertexD1 == (size-1) &&
vertexDn_1 == 1);
}

// driver code
int main()
{
int mat[size][size] = { {0, 1, 1, 1},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0}};

checkStar(mat) ? cout << "Star Graph" :
cout << "Not a Star Graph";
return 0;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ void display(int mult[][10], int rowFirst, int columnSecond)
cout << endl << endl;
}
}
}
O
}
File renamed without changes.
46 changes: 23 additions & 23 deletions C++ Problem/sum of row.cpp → C++ Problem/Arrays/sum of row.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include <iostream>
using namespace std;
int main()
{
const int x=2;
const int y=3;
int arary[x][y]={1,4,7,8,5,2};
for (int i=0;i< x;i++)
{
int sum=0;
{
for (int j=0;j<y;j++)
{
sum+=arary[i][j];
}
}
cout<<"sum of row "<<i+1<<" "<<sum;
cout<<endl;
}
#include <iostream>
using namespace std;

int main()
{
const int x=2;
const int y=3;
int arary[x][y]={1,4,7,8,5,2};
for (int i=0;i< x;i++)
{
int sum=0;
{
for (int j=0;j<y;j++)
{
sum+=arary[i][j];
}
}
cout<<"sum of row "<<i+1<<" "<<sum;
cout<<endl;
}



}
File renamed without changes.
92 changes: 46 additions & 46 deletions Butterfly_Pattern.cpp → C++ Problem/Basics/Butterfly_Pattern.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the value of n \n";
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
int space=2*n-2*i;
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
int space=2*n-2*i;
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the value of n \n";
cin>>n;

for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
int space=2*n-2*i;
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}

for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
int space=2*n-2*i;
for(int j=1;j<=space;j++)
{
cout<<" ";
}
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}

return 0;
}
72 changes: 36 additions & 36 deletions Diamond.cpp → C++ Problem/Basics/Diamond.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#include<iostream>
using namespace std;
int main()
{
int i,s,k,n;
cout<<"Enter the value of n \n";
cin>>n;
for(i=1,k=0;i<=n;i++,k=0)
{
for(s=1;s<=(n-i);s++)
{
cout<<" ";
}
while(k!=(2*i)-1)
{
cout<<"*";
k++;
}
cout<<"\n";
}
for(i=n-1,k=0;i>=1;i--,k=0)
{
for(s=1;s<=(n-i);s++)
{
cout<<" ";
}
while(k!=(2*i)-1)
{
cout<<"*";
k++;
}
cout<<"\n";
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i,s,k,n;
cout<<"Enter the value of n \n";
cin>>n;
for(i=1,k=0;i<=n;i++,k=0)
{
for(s=1;s<=(n-i);s++)
{
cout<<" ";
}
while(k!=(2*i)-1)
{
cout<<"*";
k++;
}
cout<<"\n";
}
for(i=n-1,k=0;i>=1;i--,k=0)
{
for(s=1;s<=(n-i);s++)
{
cout<<" ";
}
while(k!=(2*i)-1)
{
cout<<"*";
k++;
}
cout<<"\n";
}

return 0;
}
54 changes: 27 additions & 27 deletions Reverse_Pattern.cpp → C++ Problem/Basics/Reverse_Pattern.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include<iostream>
using namespace std;
int main()
{
int i,j,n;
cout<<"Enter the value of n \n";
cin>>n;
for(i=1;i<n;i++)
{
for(j=1;j<=i;j++)
{
if(j=n-i)
{
cout<<" ";
}
else
{
cout<<"*";
}
}
cout<<"\n";
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i,j,n;
cout<<"Enter the value of n \n";
cin>>n;
for(i=1;i<n;i++)
{
for(j=1;j<=i;j++)
{
if(j=n-i)
{
cout<<" ";
}
else
{
cout<<"*";
}


}
cout<<"\n";
}

return 0;
}
File renamed without changes.
Loading