Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What is the output answers
- 2
- 15 17
- 32
- Inside else 11 20
- Inside if 11 21
- 0 2 4
- Infinite 1s
- 0 0
- 0 1 3 4
- *************Nth Fibonacci
- #include<iostream>
- using namespace std;
- int main(){
- int a=1,b=1,n,ans=0;
- cin>>n;
- if(n==1)
- cout<<"1\n";
- else if(n==2)
- cout<<"2\n";
- else
- {
- for(int i=0;i<n-2;i++)
- {
- ans=a+b;
- a=b;
- b=ans;
- }
- cout<<ans<<'\n';
- }
- //Write your code here.
- }
- What is the output answers
- continue
- 1 2
- 1 2 infinite loop
- 1 2 1 2
- 1 2 4 5 1 2 4 5
- ********************All prime nos
- #include <iostream>
- using namespace std;
- void seive(int a[], int n)
- {
- for(int i=1;i<n;i++)
- a[i]=0;
- for(int i=2;i<n;i++)
- {
- for(int j=2;j<i;j++)
- if(i%j==0)
- a[i]=1;
- }
- }
- int main(){
- /* Read input as specified in the question.
- * Print output as specified in the question.
- */
- int n;
- cin>>n;
- int a[n];
- seive(a,n);
- for(int i=2;i<=n;i++)
- if(!a[i])
- cout<<i<<'\n';
- }
- **********Check Error
- Yes
- No
- 10
- Yes
- Infinite loop
- *******************Count Characters
- #include<iostream>
- using namespace std;
- int main(){
- /* Read input as specified in the question.
- * Print output as specified in the question.
- */
- char ans;
- int a,b,c;
- a=b=c=0;
- ans=cin.get();
- if(ans>='a'&&ans<='z')
- a=1;
- else if(ans>='0'&&ans<='9')
- c=1;
- else
- b=1;
- while(ans!='$')
- {
- ans=cin.get();
- if(ans>='a'&&ans<='z')
- a++;
- else if(ans>='0'&&ans<='9')
- c++;
- else
- b++;
- }
- cout<<a<<' '<<c<<' '<<--b<<'\n';
- }
- *****************Sum or Product
- #include<iostream>
- using namespace std;
- int main() {
- // Write your code here
- int n,c;
- cin>>n>>c;
- n++;
- if(c==1)
- {
- c=0;
- while(n--)
- c+=n;
- }
- else if(c==2)
- {
- c=1;
- while(n!=1)
- {
- n--;
- c*=n;
- }
- }
- else
- c=-1;
- cout<<c;
- }
- ****************Terms of AP
- #include<iostream>
- using namespace std;
- int main() {
- // Write your code here
- int n,i=1,ans;
- cin>>n;
- while(n!=0)
- {
- ans=(3*i)+2;
- i++;
- if(ans%4!=0)
- {
- cout<<ans<<' ';
- n--;
- }
- }
- }
- ****************Reverse a no
- #include<iostream>
- using namespace std;
- int main() {
- // Write your code here
- long long int n,temp=0;
- cin>>n;
- while(n!=0)
- {
- temp+=n%10;
- n/=10;
- temp*=10;
- }
- cout<<temp/10;
- }
- ******************Binary to decimal
- #include<bits/stdc++.h>
- using namespace std;
- int main() {
- // Write your code here
- long long int n,temp,i=0,ans=0;
- cin>>n;
- while(n!=0)
- {
- temp=n%10;
- if(temp)
- ans+=pow(2,i);
- i++;
- n/=10;
- }
- cout<<ans;
- }
- ***********Decimal to Binary
- /*Code by Surya a.k.a Sunny*/
- /* by https://www.codechef.com/users/spsc */
- #include <bits/stdc++.h>
- //#include <boost/multiprecision/cpp_int.hpp>
- #define lli long long
- #define pb push_back
- #define eb emplace_back
- #define pi 3.14159265358979323846
- #define MOD 1000000007
- #define unbuffer cin.clear(); cin.sync();
- #define foi(n) for(lli i=0;i<n;i++)
- #define foj(n) for(lli j=0;j<n;j++)
- #define test(T) lli T;cin>>T;while(T--)
- #define loop(i, a, b) for(int i = (a); i<= (b); i++)
- using namespace std;
- //using namespace boost::multiprecision;
- int main()
- {
- //ios_base::sync_with_stdio(false);
- //cin.tie(NULL);
- //cout.tie(NULL);
- lli n,c=0,temp=0,ans=0;
- cin>>n;
- if(!n)
- cout<<'0';
- else
- {
- while(n%2!=1)
- {
- c++;
- n/=2;
- }
- while(n!=0)
- {
- ans+=n%2;
- n/=2;
- ans*=10;
- }
- ans/=10;
- while(ans!=0)
- {
- temp+=ans%10;
- ans/=10;
- temp*=10;
- }
- temp/=10;
- //temp*=pow(10,c);
- while(c--)
- temp*=10;
- cout<<temp;
- }
- }
- *********Square Root (Integral)
- /*Code by Surya a.k.a Sunny*/
- /* by https://www.codechef.com/users/spsc */
- #include <bits/stdc++.h>
- //#include <boost/multiprecision/cpp_int.hpp>
- #define lli long long
- #define pb push_back
- #define eb emplace_back
- #define pi 3.14159265358979323846
- #define MOD 1000000007
- #define unbuffer cin.clear(); cin.sync();
- #define foi(n) for(lli i=0;i<n;i++)
- #define foj(n) for(lli j=0;j<n;j++)
- #define test(T) lli T;cin>>T;while(T--)
- #define loop(i, a, b) for(int i = (a); i<= (b); i++)
- using namespace std;
- //using namespace boost::multiprecision;
- int main()
- {
- //ios_base::sync_with_stdio(false);
- //cin.tie(NULL);
- lli n;
- cin>>n;
- cout<<(int)sqrt(n);
- }
- ************Check Number sequence
- /*Code by Surya a.k.a Sunny*/
- /* by https://www.codechef.com/users/spsc */
- #include <bits/stdc++.h>
- //#include <boost/multiprecision/cpp_int.hpp>
- #define lli long long
- #define pb push_back
- #define eb emplace_back
- #define pi 3.14159265358979323846
- #define MOD 1000000007
- #define unbuffer cin.clear(); cin.sync();
- #define foi(n) for(lli i=0;i<n;i++)
- #define foj(n) for(lli j=0;j<n;j++)
- #define test(T) lli T;cin>>T;while(T--)
- #define loop(i, a, b) for(int i = (a); i<= (b); i++)
- using namespace std;
- //using namespace boost::multiprecision;
- int main()
- {
- int n,temp,i=2,no;
- cin>>n>>temp;
- bool ans=true;
- while(i<=n)
- {
- cin>>no;
- if(no==temp)
- {
- cout<<"false";
- return 0;
- }
- i++;
- if(no<temp)
- {
- if(ans==false)
- {
- cout<<"false";
- return 0;
- }
- }
- else
- {
- if(ans==true)
- ans=false;
- }
- temp=no;
- }
- cout<<"true";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement