Ask Question

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

+3
Answers (1)
  1. 11 January, 06:37
    0
    Following are the code

    #include / /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;

    }

    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program in C that will sum all the numbers from 1 to 1000 while ignoring all numbers divisible by 10 and 5 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers