184k views
1 vote
Write a program in C that will sum all the numbers from 1 to 1000 while ignoring all numbers divisible by 10 and 5

1 Answer

2 votes

Answer:

Following are the code

#include <stdio.h>//header file

int main() // main function

{

int sum=0;// variable declaration

for(int i=1;i<=1000;i++) // iterating over the loop

{

if(i%10!=0 && i%5!=0) // check the condition & ignoring all numbers divisible by 10 and 5

sum=sum+i; // calculate sum

}

printf("%d",sum); // print sum

return 0;

}

Step-by-step explanation:

In this program we initialized an "sum " variable with "0" ,iterating over the loop and ignoring all numbers divisible by 10 and 5 and finally calculate sum.

output

400000

User KVNA
by
4.8k points