SlideShare a Scribd company logo
/*Write a C program to read in two numbers, x and n, and then compute the sum of this geometric
progression:

1+x+x2+x3+………….+xn For example: if n is 3 and x is 5, then the program computes 1+5+25+125.

Print x, n, the sum Perform error checking. For example, the formula does not make sense

for negative exponents - if n is less than 0. Have your program print an error message if n<0,

then go back and read in the next pair of numbers of without computing the sum.

Are any values of x also illegal ? If so, test for them too. */



#include<stdio.h>

#include<conio.h>

#include<math.h>



void main()

{

int s_sum,i,x,n;



clrscr();

printf("Enter the values for x and n:");

scanf("%d %d",&x,&n);



if(n<=0 || x<=0)

{

    printf("Value is not validn");

}

else
{

    printf("Value is validn");

    s_sum=1;

    for(i=1;i<=n;i++)

    {

        s_sum=s_sum+pow(x,i);

    }

    printf("Sum of series=%dn",s_sum);

}

getch();

}

More Related Content

DOCX
Programa
DOCX
Dti2143 lab sheet 9
PPTX
PUZZLE IN C PROGRAMMING
PPTX
Puzzle in c program
DOCX
C Language Programs
PDF
DOC
Add digits of number in c
PDF
Bcsl 033 data and file structures lab s3-2
Programa
Dti2143 lab sheet 9
PUZZLE IN C PROGRAMMING
Puzzle in c program
C Language Programs
Add digits of number in c
Bcsl 033 data and file structures lab s3-2

What's hot (20)

PDF
Write a complete C++ program that does the following: 1. The program will c...
PDF
Bcsl 033 data and file structures lab s3-1
PDF
Bcsl 033 data and file structures lab s2-1
PPTX
PPTX
Programming in c
PPTX
Programming in c (18 uama41)(1)
PDF
Prime number program in c
PDF
Bcsl 033 data and file structures lab s3-3
DOC
C program to add n numbers
DOCX
PDF
Yocco41
PDF
Bcsl 033 data and file structures lab s4-2
PDF
Bcsl 033 data and file structures lab s1-3
PDF
Implement a queue using two stacks.
PDF
Positive (2)
DOC
Palindrome number program c
PDF
Program in ‘C’ language to implement linear search using pointers
PDF
Bcsl 033 data and file structures lab s2-3
DOCX
Implementation of strassens
DOCX
Program persamaan kuadrat
Write a complete C++ program that does the following: 1. The program will c...
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s2-1
Programming in c
Programming in c (18 uama41)(1)
Prime number program in c
Bcsl 033 data and file structures lab s3-3
C program to add n numbers
Yocco41
Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s1-3
Implement a queue using two stacks.
Positive (2)
Palindrome number program c
Program in ‘C’ language to implement linear search using pointers
Bcsl 033 data and file structures lab s2-3
Implementation of strassens
Program persamaan kuadrat
Ad

Viewers also liked (7)

PPTX
Talking to the hand
PPT
Ten tools for the 1 to 1 classroom presentation
PPT
Work and Wealth
DOCX
Differences culture peruvian and finnish culture
PPT
BrainFingerprintingpresentation
PPT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
PPT
Primavera Cost Res Vn
Talking to the hand
Ten tools for the 1 to 1 classroom presentation
Work and Wealth
Differences culture peruvian and finnish culture
BrainFingerprintingpresentation
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
Primavera Cost Res Vn
Ad

Similar to week-9x (20)

PDF
Progr2
PPTX
Program presentation
DOCX
Esg111 midterm review
DOCX
C programs
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DOCX
C programs
PPTX
C programming BY Mazedur
PDF
Progr3
PDF
operating system ubuntu,linux,MacProgram will work only if you g.pdf
DOC
Md university cmis 102 week 4 hands on lab new
PPTX
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
DOC
Md university cmis 102 week 4 hands on lab new
DOC
Md university cmis 102 week 4 hands on lab new
PDF
25422733 c-programming-and-data-structures-lab-manual
PDF
C Programming Lab.pdf
PDF
#includestdio.h #includestring.h #includemath.h #include.pdf
PDF
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
Progr2
Program presentation
Esg111 midterm review
C programs
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
C programs
C programming BY Mazedur
Progr3
operating system ubuntu,linux,MacProgram will work only if you g.pdf
Md university cmis 102 week 4 hands on lab new
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
25422733 c-programming-and-data-structures-lab-manual
C Programming Lab.pdf
#includestdio.h #includestring.h #includemath.h #include.pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf

More from KITE www.kitecolleges.com (20)

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Lesson notes of climatology university.
Complications of Minimal Access Surgery at WLH
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
GDM (1) (1).pptx small presentation for students
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Microbial diseases, their pathogenesis and prophylaxis
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
Yogi Goddess Pres Conference Studio Updates
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Lesson notes of climatology university.

week-9x

  • 1. /*Write a C program to read in two numbers, x and n, and then compute the sum of this geometric progression: 1+x+x2+x3+………….+xn For example: if n is 3 and x is 5, then the program computes 1+5+25+125. Print x, n, the sum Perform error checking. For example, the formula does not make sense for negative exponents - if n is less than 0. Have your program print an error message if n<0, then go back and read in the next pair of numbers of without computing the sum. Are any values of x also illegal ? If so, test for them too. */ #include<stdio.h> #include<conio.h> #include<math.h> void main() { int s_sum,i,x,n; clrscr(); printf("Enter the values for x and n:"); scanf("%d %d",&x,&n); if(n<=0 || x<=0) { printf("Value is not validn"); } else
  • 2. { printf("Value is validn"); s_sum=1; for(i=1;i<=n;i++) { s_sum=s_sum+pow(x,i); } printf("Sum of series=%dn",s_sum); } getch(); }