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

5 questions of Function And Arrays #248

Merged
merged 5 commits into from
Oct 23, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>
#include<cmath>
using namespace std;
int AnyToDec(int n, int b) {
int d,r,s=0,i=0,t;
while(n!=0){
t=pow(b,i);
r=n%10;
s=s+(r*t);
i++;
n=n/10;}
return s;
}
int main() {
int n;
int b;
cin >> n;
cin >> b;
int res = AnyToDec(n, b);
cout << res << endl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<iostream>
#include<cmath>
using namespace std;
int DecToAny(int n, int b) {
int i=0,d,r,s=0;
while(n != 0)
{
d = n % b;
s = s + d * pow(10.0,i);
n = n / b;
i++;
}
return s;
}
int main() {
int n;
int b;
cin >> n;
cin >> b;
int res = DecToAny(n, b);
cout << res << endl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
#include<cmath>
using namespace std;
int digFreq(int n,int d)
{
int r, c = 0;
while(n != 0)
{
r = n % 10;
if(r == d)
c++;
n=n/10;
}
return c;
}
int main() {
int n, d;
cin >> n >> d;
long int r;
r=pow(10.0,9.0);
if(n >= 0 && n <= r && d >= 0 && d <= 9)
{
int res = digFreq(n, d);
cout << res << endl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<iostream>
#include <cstdlib>
using namespace std;
int main() {
int x, n,i,j,el,k=-1;
cin >>n;
int *arr ;
arr = (int*)malloc(n*sizeof(int));
for (x = 0; x < n; x++) {
cin >> arr[x];
}
cin >> el;
for(i=0;i<n;i++)
{
if(arr[i]==el)
k=i;
}
cout<<k;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
#include <cstdlib>
using namespace std;
int main() {
int x, n,i,k,max,min;
cin >>n;
int *arr ;
arr = (int*)malloc(n*sizeof(int));
for (x = 0; x < n; x++) {
cin >> arr[x];
}
min=arr[0];
max=arr[0];
for(i=1;i<n;i++)
{
if(min>arr[i])
min = arr[i];

if(max<arr[i])
max = arr[i];
}
k = max - min;
cout << k;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include<cmath>
using namespace std;

int main(){
int n;
cin >> n;
if(n>=1 && n<=pow(10.0,9.0)){
int d=0;
while(n!=0)
{
n=n/10;
d++;
}
cout<<d;
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include<cmath>
using namespace std;

int main(int argc, char **argv){
int n,c=0;
cin >> n;
int m,i,j;
m=n;
while(n != 0)
{
c++;
n = n / 10;
}
c = c - 1;
i = pow (10.0,c);
while(i!=0)
{
cout << m/i << endl;
m = m % i;
i = i / 10;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;

int main()
{
int n1, n2, i;
int gcd = 1, lcm = 1;


cin >> n1 >> n2;
for ( i = 1; i < 1000; i++)
{ if ((n1 % i == 0) && (n2 % i == 0))
{
gcd = i;
}
}

lcm = (n1 * n2) / gcd;
cout << gcd << endl << lcm <<endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>

using namespace std;

int main()
{
int a;
cin>>a;
if(a>90)
cout<<"excellent"<<endl;
else if(a<=90 && a>80)
cout<<"good"<<endl;
else if(a>70 && a<=80)
cout<<"fair"<<endl;
else if(a>60 && a<=70)
cout<<"meets expectations"<<endl;
else
cout<<"below par"<<endl;


return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char **argv){
int n;
cin >> n;
int d = 0 , lo,m,i,j,t,k=0;
int *arr,*arr2;
m = n;
while(m != 0)
{
d++;
m = m/10;
}
arr = (int*)malloc(d*sizeof(int));
arr2 = (int*)malloc(d*sizeof(int));
m = n;
while(m!=0)
{
arr[k] = m % 10;
m = m / 10;
k++;
}

for(j=0;j<d;j++)
{
int l = arr[j];
arr2[l-1] = j+1;
}

for(j=d-1;j>=0;j--)
cout << arr2[j] ;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include<cmath>
using namespace std;
int main(){
int t,i,j,n,c;
cin >> t;
if(t>=1 && t<=10000)
{
for (i=0;i<t;i++)
{
c=0;
cin>>n;
if(n>=2 && n<=pow(10,9))
{

for(j=1;j<=n;j++)
{
if(n%j==0)
c++;

}
if(c==2)
cout<<"prime"<<endl;
else
cout<<"not prime"<<endl;
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char **argv){
int low, high, i,j,c=0;
cin >> low >> high;
for(i=low;i<=high;i++)
{c=0;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
c++;
}
if(c==0)
cout<<i<<endl;
}
return 0;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
int n,c;
cin >> n;
int a=0,b=1;
cout<<a<<endl<<b<<endl;
for(int i=0;i<n-2;i++)
{
c=a+b;
cout<<c<<endl;
a=b;
b=c;
}


}
29 changes: 29 additions & 0 deletions IOT/Nivedita-R_NiveditaRai_2125it1079_2/GettingStarted/PrintZ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#include <iostream>

using namespace std;

int main()
{
int i,j,k;
for(i=0;i<5;i++)
{
for(j=4;j>=0;j--)
{
if(i==0 || i==4)
cout<<"*";
else
{
if(i==j)
cout<<"*";
else
cout<<" ";
}

}
cout<<endl;
}

return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include<cmath>
using namespace std;

int main(){
int n;
cin >> n;

int d;
while(n != 0)
{
d = n % 10;
cout << d << endl;
n = n / 10;
}
return 0;

}
Loading