C programming code to add all numbers divisible by 3 from 1 to 1000

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to add all numbers divisible by 3 from 1 to 1000

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float sum=0;
for(int i=1;i<=1000;i++)
{
if(i%3==0)
sum=sum+i;
}
printf(“The sum of all numbers divisible by 3 from 1 to 1000 is %.2f.”,sum);
getch();
}

Share this article:
Previous Post: C programming code to display the first n even numbers

December 2, 2014 - In Academics, Computers

Next Post: C programming code to list all factors of n

December 2, 2014 - In Academics, Computers

Related Posts

Leave a Reply

Your email address will not be published.