w3resource

C Exercises: Find the number and sum of all integer between 100 and 200, divisible by 9

C For Loop: Exercise-39 with Solution

Write a program in C to find the number and sum of all integers between 100 and 200 which are divisible by 9.

Visual Presentation:

Check whether a number is a palindrome or not

C Code:

#include <stdio.h> // Include the standard input/output header file.

int main()
{
   int i, sum=0; // Declare variables for iteration and sum.

   printf("Numbers between 100 and 200, divisible by 9 : \n"); // Print a message to indicate the output format.

   for(i=101; i<200; i++) // Loop through numbers from 101 to 199.
   {
     if(i%9==0) // Check if the current number is divisible by 9.
     {
       printf("% 5d", i); // Print the number with formatting.
       sum += i; // Add the divisible number to the sum.
     }
   }

   printf("\n\nThe sum : %d \n", sum); // Print the total sum of divisible numbers.
    return 0;  // Indicate that the program has executed successfully.
}

Sample Output:

Numbers between 100 and 200, divisible by 9 :                                                                 
  108  117  126  135  144  153  162  171  180  189  198                                                       
                                                                                                              
The sum : 1683 

Flowchart:

Flowchart : Find the number and sum of all integer between 100 and 200, divisible by 9

C Programming Code Editor:

Previous: Write a program in C to check whether a number is a palindrome or not.
Next: Write a C Program to display the pattern like pyramid using the alphabet.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.