Friday, June 10, 2016

URI Online Judge Solution 1132 || Multiples of 13

URI Online Judge | 1132

Multiples of 13

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Write a program that reads two integer numbers X and Y and calculate the sum of all number not divisible by 13 between them, including both.

Input

The input file contains 2 integer numbers X and Y without any order.

Output

Print the sum of all numbers between X and Y not divisible by 13, including them if it is the case.
Input SampleOutput Sample
100
200
13954


URI Online Judge Solution 1132 || Multiples of 13 in C language


#include<stdio.h>
int main(){
    int X, Y, i;
    scanf("%d%d", &X,&Y);
    if (X > Y) {
        int total = 0;
        for (i = Y; i <= X; i++) {
            if (i % 13 != 0) {
                total += i;
            }
        }
        printf("%d\n", total);
    }else if(X < Y){
        int total2 = 0;
        for (i = X; i <= Y; i++) {
            if (i % 13 != 0) {
                total2 +=i;
            }
        }

        printf("%d\n", total2);
    }

}



URI Online Judge Solution 1132 || Multiples of 13 in Java language





import java.io.IOException;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        int X, Y;
        Scanner input =new Scanner(System.in);
        X = input.nextInt();
        Y = input.nextInt();
        if (X > Y) {
            int total = 0;
            for (int i = Y; i <= X; i++) {
                if (i % 13 != 0) {
                    total +=i;
                }
            }
            System.out.print(total+"\n");
        }else if(X < Y){
            int total2 = 0;
            for (int i = X; i <= Y; i++) {
                if (i % 13 != 0) {
                    total2 +=i;
                }
            }
 
            System.out.print(total2+"\n");
        }
         
    }
}


URI Online Judge Solution 1132 || Multiples of 13 in C++language


#include <iostream>

using namespace std;

int main()
{
    int x, y, min, max;
    int tmp = 0;

    cin >> x >> y;

    if(x < y){
        min = x;
        max = y;
    }else{
        min = y;
        max = x;
    }

    for (int i = min; i <= max; ++i)
    {
        if(i % 13 != 0)
            tmp += i;
    }

    cout << tmp << endl;

    return 0;
}



Download code from submitted Dropbox code
URI Main Link :


1 comment:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.