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 <= 99999991 <= 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 3Output
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 5Output
21 16 11 6 1Explanation
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