Codeabbey Volume Beginners Solutions 1-6, 15

Intro:

These are some of the basic programming problems. Also these are the very fundamentals to start solving more complex problems. I will include more problems if I have time.

These problems are from codeabbey volume beginners level and problems 1 to 6 and number 15.


Task: Sum “A+B” :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<iostream>
using namespace std;
int main(){
    long long a,b;
    while(cin >> a >> b){
        cout << a+b << "\n";
    }
    return 0;
}

Task: Sum in Loop :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
int main(){
    register unsigned int n;
    while(scanf("%u", &n)==1){
        long long sum = 0;
        while(n--){
            long long ago;
            scanf("%lld", &ago);
            sum += ago;
        }
        printf("%lld\n", sum);
    }
    return 0;
}

Task: Sums in Loop :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
int main(){
    register unsigned int n;
    while(scanf("%u", &n)==1){
        while(n--){
            long long a,b;
            scanf("%lld%lld", &a, &b);
            printf("%lld", a+b);
            if(n) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Task: Minimum of Two :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
int main(){
    register unsigned int n;
    while(scanf("%u", &n)==1){
        while(n--){
            long long a,b;
            scanf("%lld%lld", &a, &b);
            a>b?printf("%lld", b):printf("%lld", a);
            if(n) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Task: Minimum of Three :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
inline long long min(long long a, long long b){
    return (a>b?b:a);
}
int main(){
    register unsigned int n;
    while(scanf("%u", &n)==1){
        while(n--){
            long long a,b,c;
            scanf("%lld%lld%lld", &a, &b, &c);
            printf("%lld", min(min(a,b),c));
            if(n) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Task: Maximum of array :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
int main(){
    register unsigned int i = 0;
    long long max, min, n;
    while(scanf("%lld", &n)==1){
        if(i){
            if(n > max){
                max = n;
            }
            if(n < min){
                min = n;
            }
        }else{
            max = n;
            min = n;
            ++i;
        }
    }
    printf("%lld %lld\n", max, min);
    return 0;
}

Task: Rounding :
/*
 * Author: Quickgrid ( Asif Ahmed )
 * Site: https://quickgrid.wordpress.com
 */
#include<stdio.h>
#include<math.h>
int main(){
    register unsigned int n;
    long long a, b;
    while(scanf("%u", &n)==1){
        while(n--){
            scanf("%lld%lld", &a, &b);
            printf("%lld", (long long) round(a/(double)b));
            if(n) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s