Decreasing Sequence from N

 Coding Problem Keys 

 Decreasing Sequence from N 

 Problem Statement 

Two integers N and D are passed as input. The program must print the decreasing sequence from N to 1 with common difference D.

 Boundary Condition(s) 

2 <= N <= 9999999
1 <= D <= 9999999

 Input Format 

The first line contains N and D separated by a space.

 Output Format 

The first line contains integers separated by a space.

 Example Input/Output 1 

 Input 

20 3

 Output 

17 14 11 8 5 2

 Explanation 

The output is obtained by the cyclic manner of reducing value of 20 with 3 which is separated by space.

 Example Input/Output 2 

 Input 

26 5

 Output 

21 16 11 6 1

 Explanation 

The output is obtained by the cyclic manner of reducing value of 26 with 5 which is separated by space.

 Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

n,d=map(int,input().split())
for i in range(n-d,0,-d):
    print(i,end=" ")

# Published By PKJCODERS

 Programming Language: C Language 

#include<stdio.h>
#include <stdlib.h>
int main(){
    int n,i,m;
    scanf("%d %d",&n,&m);
    for(i=n-m;i>=1;i-=m){
        printf("%d ",i);
    }
}

// Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Function decimalToBinary - CTS Pattern

Flowchart Logic 047

Interface Implementation - Pair

Max Winning Streak Game Points

Bank Account Balance

Desktop Products