Page 100 - CA_Blue( J )_Class9
P. 100
You will get the following output:
In the above program, the counter variable increases by 1 when the number 47 is divisible by the current value of i
which is starting from 1 to 47. In case of prime number, the value of the counter should be 2. In this case, the value
is 2 as 47 is a prime number. So, the output is 47 is a prime digit.
Accumulator
An accumulator is a variable that stores a running total or accumulated value, often used to sum values within a loop.
Unlike counters, which typically increment by a fixed amount, accumulators can add varying values to their total,
depending on the logic of the program. They are also initialized to 0 (or another starting value as required by the logic)
before the accumulation process begins.
Program 16 Write a program to sum of all numbers from 10 to 20.
1 class sum_of_number
2 {
3 public static void main()
4 {
5 int s=0,i;
6 for(i=10;i<=20;i++)
7 {
8 s=s+i;
9 }
10 System.out.println("Sum:" + s);
11 }
12 }
You will get the following output:
98 Touchpad Computer Applications-IX

