Computer Science, asked by arpeetamohanty, 3 months ago

WAPP to print the sum of first n natural numbers, each of which is neither multiples of 7, nor of 6. using for loop

Answers

Answered by Oreki
2

Code:

   import java.util.Scanner;

   public class NaturalNumbers {

       public static void main(String[ ] args) {

           System.out.print("Enter N - ");

           int N = new Scanner(System.in).nextInt( ), sum = 0;

           for (int i = 1; i <= N; i++)

               if (!(i % 7 == 0 || i % 6 == 0))

                   sum += i;

           System.out.println("Sum - " + sum);

       }

   }

Sample I/O:

   Enter N - 30

   Sum - 305

Answered by jai696
2

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

def _sum(n):

_sum = 0

for i in range(1, n + 1):

if i % 6 != 0 and i % 7 != 0:

print(i)

_sum += i

return _sum

print(_sum(int(input("n: "))))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions