Program to print series 10,5,60,15,110...N

Problem statement:- Program to print series 10,5,60,15,110...N.

 Data requirement:-

   Input Data:- n

  Output Data:- a, b

  Additional Data:- i, k, p

Program in C
  
Here is the source code of the C Program to print series 10,5,60,15,110...N.

Code:

#include<stdio.h>
int main()
{
    int n,i,a=10,b=5;
    printf("Enter the range of number:");
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
     if(i%2==0){
        printf("%d ",b);
        b+=10;
     }
     else
     {
         printf("%d ",a);
        a+=50;
     }
    }

}

Input/Output:
Enter the range of number:5
10 5 60 15 110
Program in C++
  
Here is the source code of the C++ Program to print series 10,5,60,15,110...N.

Code:

#include<iostream>
using namespace std;
int main()
{
    int n,i,a=10,b=5;
    cout<<"Enter the range of number:";
    cin>>n;
    for(i=1;i<=n;i++)
    {
     if(i%2==0){
        cout<<b<<" ";
        b+=10;
     }
     else
     {
         cout<<a<<" ";
        a+=50;
     }
    }
}

Input/Output:
Enter the range of number:7
10 5 60 15 110 25 160

Program in Java
  
Here is the source code of the Java Program to print series 10,5,60,15,110...N.

Code:

import java.util.Scanner;
public class p28 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,a=10,b=5;
    System.out.println("Enter the range of number:");
    n=cs.nextInt();
    for(i=1;i<=n;i++)
    {
     if(i%2==0){
        System.out.print(b+" ");
        b+=10;
     }
     else
     {
        System.out.print(a+" ");
        a+=50;
     }
    }
    cs.close();
}
}

Input/Output:
Enter the range of number:
9
10 5 60 15 110 25 160 35 210 

Program in Python
  
Here is the source code of the C Program to print series 10,5,60,15,110...N.

Code:

print("Enter the range of number(Limit):")
n=int(input())
a=10
b=5
i=1
while(i<=n):
    if(i%2==0):
        print(b,end=" ")
        b += 10
    else:
        print(a, end=" ")
        a += 50
    i+=1

Input/Output:
Enter the range of number(Limit):
12
10 5 60 15 110 25 160 35 210 45 260 55 

Post a Comment

0 Comments