Problem statement:- Program to print Arithmetic series 1 4 7 10...N
Data requirement:-
Input Data:- first_num, n ,diff
Output Data:-first_num
Program in C
Here is the source code of the C Program to print Arithmetic series 1 4 7 10...N.
Code:
#include<stdio.h>
int main()
{
int n,first_num,diff;
printf("Enter the First Number:");
scanf("%d",&first_num);
printf("Enter the range of number(Limit):");
scanf("%d",&n);
printf("Enter the Difference Between two Number:");
scanf("%d",&diff);
while(first_num<=n)
{
printf("%d ",first_num);
first_num+=diff;
}
}
int main()
{
int n,first_num,diff;
printf("Enter the First Number:");
scanf("%d",&first_num);
printf("Enter the range of number(Limit):");
scanf("%d",&n);
printf("Enter the Difference Between two Number:");
scanf("%d",&diff);
while(first_num<=n)
{
printf("%d ",first_num);
first_num+=diff;
}
}
Input/Output:
Enter the First Number:1
Enter the range of number(Limit):11
Enter the Difference Between two Number:3
1 4 7 1
Enter the range of number(Limit):11
Enter the Difference Between two Number:3
1 4 7 1
Program in C++
Here is the source code of the C++ Program to print Arithmetic series 1 4 7 10...N.
Code:
#include<iostream>
using namespace std;
int main()
{
int n,first_num,diff;
cout<<"Enter the First Number:";
cin>>first_num;
cout<<"Enter the range of number(Limit):";
cin>>n;
cout<<"Enter the Difference Between two Number:";
cin>>diff;
while(first_num<=n)
{
cout<<first_num<<" ";
first_num+=diff;
}
}
Input/Output:
Enter the First Number:3
Enter the range of number(Limit):21
Enter the Difference Between two Number:4
3 7 11 15 19
Enter the range of number(Limit):21
Enter the Difference Between two Number:4
3 7 11 15 19
Program in Java
Here is the source code of the Java Program to print Arithmetic series 1 4 7 10...N.
Code:
import java.util.Scanner;
public class p7 {
public static void main(String[] args) {
int n,first_num,diff;
Scanner cs=new Scanner(System.in);
System.out.println("Enter the First Number:");
first_num=cs.nextInt();
System.out.println("Enter the range of number(Limit):");
n=cs.nextInt();
System.out.println("Enter the Difference Between two Number:");
diff=cs.nextInt();
while(first_num<=n)
{
System.out.print(first_num+" ");
first_num+=diff;
}
cs.close();
}
}
public class p7 {
public static void main(String[] args) {
int n,first_num,diff;
Scanner cs=new Scanner(System.in);
System.out.println("Enter the First Number:");
first_num=cs.nextInt();
System.out.println("Enter the range of number(Limit):");
n=cs.nextInt();
System.out.println("Enter the Difference Between two Number:");
diff=cs.nextInt();
while(first_num<=n)
{
System.out.print(first_num+" ");
first_num+=diff;
}
cs.close();
}
}
Input/Output:
Enter the First Number:
7
Enter the range of number(Limit):
33
Enter the Difference Between two Number:
6
7 13 19 25 31
7
Enter the range of number(Limit):
33
Enter the Difference Between two Number:
6
7 13 19 25 31
Program in Python
Here is the source code of the Python Program to print Arithmetic series 1 4 7 10...N.
Code:
print("Enter the First Number:")
first_num=int(input())
print("Enter the range of number(Limit):")
n=int(input())
print("Enter the Difference Between two Number:")
diff=int(input())
while(first_num<=n):
print(first_num,end=" ")
first_num+=diff
first_num=int(input())
print("Enter the range of number(Limit):")
n=int(input())
print("Enter the Difference Between two Number:")
diff=int(input())
while(first_num<=n):
print(first_num,end=" ")
first_num+=diff
Input/Output:
Enter the First Number:
11
Enter the range of number(Limit):
71
Enter the Difference Between two Number:
7
11 18 25 32 39 46 53 60 67
11
Enter the range of number(Limit):
71
Enter the Difference Between two Number:
7
11 18 25 32 39 46 53 60 67
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box