Problem statement:- Program to Find the sum of series 3+33+333+3333.....+N.
Data requirement:-
Input Data:- n
Output Data:-Sum
Additional Data:- i, p
Program in C
Here is the source code of the C Program to Find the sum of series 3+33+333+3333.....+N.
Code:
#include<stdio.h>
int main()
{
int n;
int sum=0,i;
printf("Enter the range of number:");
scanf("%d",&n);
int p=3;
for(i=1;i<=n;i++)
{
sum+=p;
p=(p*10)+3;
}
printf("The sum of the series = %d",sum);
}
Enter the range of number:4
The sum of the series = 3702
Program in C++
Here is the source code of the C++ Program to Find the sum of series 3+33+333+3333.....+N.
Code:
#include<iostream>
using namespace std;
int main()
{
int n;
int sum=0,i;
cout<<"Enter the range of number:";
cin>>n;
int p=3;
for(i=1;i<=n;i++)
{
sum+=p;
p=(p*10)+3;
}
cout<<"The sum of the series = "<<sum;
}
Enter the range of number:8
The sum of the series = 37037034
Program in Java
Here is the source code of the Java Program to Find the sum of series 3+33+333+3333.....+N.
Code:
import java.util.Scanner;
public class Sum_Of_Series8 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n;
int sum=0,i;
System.out.println("Enter the range of number:");
n=cs.nextInt();
int p=3;
for(i=1;i<=n;i++)
{
sum+=p;
p=(p*10)+3;
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
Enter the range of number:
5
The sum of the series = 37035
Program in Python
Here is the source code of the Python Program to Find the sum of series 3+33+333+3333.....+N.
Code:
n=int(input("Enter the range of number:"))
sum=0
p=3
for i in range(1,n+1):
sum += p
p=(p*10)+3
print("The sum of the series = ",sum)
Enter the range of number:10
The sum of the series = 3703703700
Most Recommend Questions:-
More Questions:-
2 Comments
333333
ReplyDelete333336
ReplyDeletePlease do not Enter any spam link in the comment box