Generation

generate functionWed, 25 Jan 2023

Given three numbers A, B and X. Print the summation of numbers between A and B inclusive that are divisible by X.

#include<iostream> using namespace std; int main() { int a,b,x,sum=0,i; cin>>a>>b>>x; for(i=a;i<=b;i++) { if(i%x == 0) { sum = sum+i; } } cout<<sum; return 0; }

Questions about programming?Chat with your personal AI assistant