Computer Science, asked by sangitajaiswal2903, 7 months ago

print the following series 1,2,3,4......upto n terms​

Answers

Answered by aishikaroy
2

FOR ANY PROGRAMMING LANGUAGE THAT YOU ARE USING , THE FOLLOWING LOGIC SHOULD WORK.

use a for loop and make it run n times .

take the value of n from the user.

I'm writing the solution in python and java but you can convert the syntax in the language that you are using and it should work .

For python

n=int(input("Enter a number : "))

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

     print(i)

For java

public class Myclass

{

  public static void main (string[ ] args)

  {

     Scanner sc= new Scanner(System.in);    

     System.out.print("Enter a number- ");

     int n= sc.nextInt();

     for (int i = 1; i =n; i++)

    {

             System.out.println(i);

   }

 }

}

hope it helps

Similar questions