Answers for "sum of the multiples of two numbers below n algorithm"

C
1

find sum of multiples of a number up to N

// C# program to find sum of multiples
// of a number up to N efficiently
using System;
 
class GFG {
 
    // Function for calculating sum
    // of multiples of a upto N
    static int calculate_sum(int a, int N)
    {
 
        // Number of multiples
        int m = N / a;
 
        // sum of first m natural numbers
        int sum = m * (m + 1) / 2;
 
        // sum of multiples
        int ans = a * sum;
 
        return ans;
    }
 
    // Driver code
    public static void Main()
    {
 
        int a = 7, N = 49;
        Console.WriteLine("Sum of multiples of " + a +
         " up to " + N + " = " + calculate_sum(a, N));
    }
}
Posted by: Guest on January-04-2022
1

how to find sum of two nums

#include<stdio.h>
int main() {
int a, b, sum;
printf("nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
Posted by: Guest on December-22-2020

Code answers related to "sum of the multiples of two numbers below n algorithm"

Code answers related to "C"

Browse Popular Code Answers by Language