Ask Question
6 April, 23:42

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
Answers (1)
  1. 7 April, 00: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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers