Skip to content
Open
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
35 changes: 35 additions & 0 deletions Contests/codechef solutions/Chef_Diet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Problem Link : https://www.codechef.com/problems/DIET

#include <iostream>
using namespace std;

int main() {
// your code goes here
int T,N,i,flag;
long K;
cin>>T;
while(T--)
{
cin>>N>>K;
long A[N],Sum;
// Used Sum variable here to represent left over from previous iteration
Sum=0;
for(i=1;i<=N;i++)
cin>>A[i];
for(i=1;i<=N;i++)
{
flag=0;
if((Sum+A[i])<K)
{
flag=i;
break;
}
Sum=Sum+(A[i]-K);
}
if(flag!=0)
cout<<"NO"<<" "<<flag<<"\n";
else
cout<<"YES"<<"\n";
}
return 0;
}
16 changes: 16 additions & 0 deletions Cpp/Maths/Average.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the size of array : ";
cin>>n;
int a[n],i,average;
float sum=0;
cout<<"Enter array elements : \n";
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
sum=sum+a[i];
cout<<"Average : "<<(sum/n);
}
25 changes: 25 additions & 0 deletions Cpp/Programs/Diamond_Pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
using namespace std;
int main()
{
int r,i,j,k;
cout<<"Enter no. of rows after which u want to mirror image below of above : ";
cin>>r;
cout<<"Diamond Pattern : \n";
for(i=1;i<=r;i++)
{
for(j=1;j<=r-i;j++)
cout<<" ";
for(k=1;k<=((2*i)-1);k++)
cout<<"*";
cout<<"\n";
}
for(i=1;i<r;i++)
{
for(j=1;j<=i;j++)
cout<<" ";
for(k=1;k<=((2*r)-(2*i)-1);k++)
cout<<"*";
cout<<"\n";
}
}
36 changes: 36 additions & 0 deletions Cpp/Programs/Matrix_Transpose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
using namespace std;
int main()
{
int r,c,i,j;
cout<<"Enter rows : ";
cin>>r;
cout<<"Enter columns : ";
cin>>c;
int A[r][c],B[c][r];
cout<<"Enter matrix elements : \n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cin>>A[i][j];
}
cout<<"Matrix A : \n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
cout<<A[i][j]<<"\t";
cout<<"\n";
}
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
B[i][j]=A[j][i];
}
cout<<"Transpose Of Matrix A : \n";
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
cout<<B[i][j]<<"\t";
cout<<"\n";
}
}
Binary file added a.exe
Binary file not shown.