Write a program to count the Number of times digit 3 occurs in each and every number from 0 to n.
Example:
Input: num = 30
Output: Count of three in each number is
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1
C Program
#include <stdio.h>int main(){int num = 30;int threeCount[num + 1];for (int i = 0; i <= num; i++){threeCount[i] = 0;}for (int i = 1; i <= num; i++){int j = i;while (j > 0){int temp = j % 10;if (temp == 3){threeCount[i]++;}j = j / 10;}}printf("Count of three in each number is\n");for (int i = 0; i <= num; i++){printf("%d ", threeCount[i]);}return 0;}
No comments:
Post a Comment