Facebook
From Adjowa Asamoah, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 130
  1. int initialValue = 6; // Initial integer value
  2.  
  3. void setup() {
  4.   size(600, 600);
  5.   background(255);
  6.   int sumOfOdd = 0; // Initialize sum of odd numbers
  7.  
  8.   // Loop through numbers from 0 to initialValue
  9.   for (int i = 0; i <= initialValue; i++) {
  10.     if (i % 2 == 0) {
  11.       // If the number is even, display it on the canvas
  12.       fill(0);
  13.       textSize(20);
  14.       text(i, 50 + i * 50, 100);
  15.     } else {
  16.       // If the number is odd, add it to the sum
  17.       sumOfOdd += i;
  18.     }
  19.   }
  20.  
  21.   // Display the sum of odd numbers
  22.   fill(255, 0, 0);
  23.   textSize(20);
  24.   text("Sum of odd numbers: " + sumOfOdd, 200, 150);
  25.  
  26.   save("activity10.png");
  27. }
  28.