C Programming (Turbo / Visual C++ Compiler) - Display the numbers containing the digit '5' in between 100 to 200
I have given here a C program to display the numbers containing the digit '5' in between 100 to 200. The idea here is to use the mod and divide operator to get the single digit and check whether it is equal to 5 or not.
Source Code
#include <stdio.h>
int main()
{
int sum = 0;
int i, a, b, c;
for(i = 100; i <= 200; i++)
{
a = i % 100;
b = a / 10;
c = a % 10;
if(b == 5 || c == 5)
printf("%d\n", i);
sum += i;
}
printf("\n\nSum = %d\n\n", sum);
return 0;
}
Output
105
115
125
135
145
150
151
152
153
154
155
156
157
158
159
165
175
185
195
Sum = 15150
Press any key to continue . . .
|