/* If we list all the natural numbers below 10 that
are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
#include<stdio.h>
#include<conio.h>
int main()
{
long sum=0,range=1;
clrscr();
do{
if(range%3==0 || range%5==0)
sum+=range;
range++;
}while(range<1000);
printf("\nThe sum is: %ld", sum);
getch();
return 0;
}
Answer: 233168
Hints/Background Knowledge:
are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
#include<stdio.h>
#include<conio.h>
int main()
{
long sum=0,range=1;
clrscr();
do{
if(range%3==0 || range%5==0)
sum+=range;
range++;
}while(range<1000);
printf("\nThe sum is: %ld", sum);
getch();
return 0;
}
Answer: 233168
233168
233168
233168
Hints/Background Knowledge:
Type Bytes Range ---------------------------------------------------------------
short int 2 -32,768 -> +32,767 (32kb)
unsigned short int 2 0 -> +65,535 (64Kb)
unsigned int 4 0 -> +4,294,967,295 ( 4Gb)
int 4 -2,147,483,648 -> +2,147,483,647( 2Gb)
long int 4 -2,147,483,648 -> +2,147,483,647( 2Gb)
signed char 1 -128 -> +127
unsigned char 1 0 -> +255
float 4
double 8
long double 12
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন