Ask Question
4 January, 01:12

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

+5
Answers (1)
  1. 4 January, 01:55
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers