This C Program will accept number accept range from user and then print numbers which are divisible by 3 or 5.
In this program we have accepted range from user. After that using mod operator and for loop we are printing numbers which are divisible by 3 or 5. Compile and Run below program to get the output.
#include <stdio.h>
int main() {
int rangeNo;
printf("Enter number upto which you need to find number divisible by 3 or 5");
scanf("%d",&rangeNo);
//Loop to print number which are divisible by 3
printf("\n\nThese numbers are divisible by 3\n\n\t\t");
for (int i = 1;i<=rangeNo;i++)
{
if (i%3==0)
printf("\t%d",i);
}
printf("\n\nThese numbers are divisible by 5\n\n\t\t");
for (int i = 1;i<=rangeNo;i++)
{
if (i%5==0)
printf("\t%d",i);
}
return 0;
}
Output
Enter number upto which you need to find number divisible by 3 or 5300
These numbers are divisible by 3
3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108
111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162
165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216
219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270 273 276 279 282 285 288 291 294 297 300
These numbers are divisible by 5
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85
90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175
180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265
270 275 280 285 290 295 300