Source Code:
//Write a program in C to find the sum of the series 1 +11 + 111 + 1111 + .. n terms
#include <stdio.h>
int main()
{
int n, i; /* n is number of terms as input and i is a variable*/
long sum=0; /* sum is a variable to store the sum and give as output */
printf("Enter the n th term: ");
scanf("%d",&n); /*Input the number of terms */
int k=0;
for(i=0;i<n;i++)
{
k=(k*10)+1;
sum=sum+k;
}
printf("%ld",sum);
return 0;
}
Output:
No comments:
Post a Comment