Skip to main content

Posts

Showing posts with the label ctf programming

Input and Output hackerrank

Input and Output     #include < cmath > #include < cstdio > #include < vector > #include < iostream > #include < algorithm > using namespace std; int main() { int a, b, c, d; cin >> a>>b>> c; d = a+b+c; cout<< d; return 0 ; }  

Pointer -hackerrank (challenges writeup)

Pointer -hackerrank (challenges writeup)  Pointer https://www.hackerrank.com/challenges/c-tutorial-pointer/problem #include<iostream> using namespace std; void func(int *z,int *f) {    int aa = *z;    *z = *z + *f;    *f = aa- *f;       if(*f < 0)*f *= -1;    } int main() {     int a, b;     int *pa = &a, *pb = &b;     cin >> a>> b;     func(pa,pb);     cout <<a<<endl;     cout<< b; }

Functions c++ - hackerrank

  https://www.hackerrank.com/challenges/c-tutorial-functions/problem #include <iostream> #include <cstdio> using namespace std; int max_of_four(int a, int b, int c, int d) {    if (a >= b &&  a>=c && a>=d)       return a;    else if(b>=a && b>=c && b>=d )       return b;    else if(c>=a&& c>=b && c>= d)       return c;    else       return d; }; int main() {    int a,b,c,d;    scanf("%d %d %d %d", &a, &b, &c, &d);     int vv = max_of_four(a,b,c,d);     printf ("%d", vv);     return 0; }

For Loop - c++ hackerrank

For Loop https://www.hackerrank.com/challenges/c-tutorial-for-loop/problem #include <iostream> using namespace std; int main() {    int a, s,i;    cin >>i;    cin>> a;    for(i; i<=a; i++)    {       if(i==1)       {          cout<< "one\n";       }       else if(i==2)       {          cout<< "two\n";       }       else if(i==3)       {          cout<< "three\n";       }       else if(i==4)       {          cout<< "four\n";    ...

Conditional Statements C++ - hackerrank

https://www.hackerrank.com/challenges/c-tutorial-conditional-if-else/problem #include <bits/stdc++.h> using namespace std; int main() {     int n;     cin >> n;         //cin.ignore(numeric_limits<streamsize>::max(), '\n');      if(n == 1)       cout << "one";    else if(n == 2){       cout << "two";    }    else if(n== 3){       cout << "three";    }    else if(n == 4){       cout << "four";    }    else if(n == 5){       cout << "five";    }    else if(n == 6){       cout << "six";    }    else if(n ==7){       cout << "seven";    }    else if(n ...

Basic Data Types C++ - hackerrank

Basic Data Types  https://www.hackerrank.com/challenges/c-tutorial-basic-data-types/problem #include <iostream> #include <cstdio> using namespace std; int main() { int i; long l; char c; float f; double d; scanf("%d %ld %c %f %lf", &i, &l, &c, &f, &d); printf("%d\n%ld\n%c\n%0.3f\n%0.9lf\n", i, l, c, f, d); return 0; }

Codewars — Sum of the first nth term of Series

Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... Rules: You need to round the answer to 2 decimal places and return it as String. If the given value is 0 then it should return 0.00 You will only be given Natural Numbers as arguments. Examples: SeriesSum(1) => 1 = "1.00" SeriesSum(2) => 1 + 1/4 = "1.25" SeriesSum(5) => 1 + 1/4 + 1/7 + 1/10 + 1/13 = "1.57"     My Solution     #include <iostream> #include <iomanip> using namespace std; class ta { float ar[50]; int j,f,k,q; float sum=0.00; public: void taa(int k) { f = k; } void paa() { for(j=0; j<f; j++) { ar[j] = 1.00/(1 + j * 3); } } void baa() { for(q=0; q<f; q++) { sum = sum+ar[q]; } cout <<setprecision(3)<< sum; ...