SlideShare a Scribd company logo
1 of 8
Download to read offline
1
1. Write a c program to swap two numbers.
void main()
{
int a,b,c;
clrscr();
printf("n Enter two no ");
scanf("%d%d",&a,&b);
printf("n Before Swaping value of a and b %d %d",a,b);
c=a;
a=b;
b=c;
printf("n After Swaping value of a and b %d %d",a,b);
getch();
}
2. Write a c program to swap two numbers without using third
variable.
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a= %d b= %d",a,b);
return 0;
getch();
}
3. Write a c program to swap two numbers without using third
variable.
#include<stdio.h>
#include<conio.h>
int main()
{
int a=5,b=10;
//process one
a=b+a;
2
b=a-b;
a=a-b;
printf("a= %d b= %d",a,b);
return 0;
getch();
}
1. How to calculate power of a number in c
#include<stdio.h>
int main(){
int pow,num,i=1;
long int sum=1;
printf("nEnter a number: ");
scanf("%d",&num);
printf("nEnter power: ");
scanf("%d",&pow);
while(i<=pow){
sum=sum*num;
i++;
}
printf("n%d to the power %d is: %ld",num,pow,sum);
return 0;
}
2. Code for swapping in c
#include<stdio.h>
int main(){
int a,b,temp;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping: a = %d, b=%d",a,b);
temp= a;
a=b;
b=a;
printf("nAfter swapping: a = %d, b=%d",a,b);
return 0;
}
3
3. Count the number of digits in c
#include<stdio.h>
int main(){
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
num=num/10;
count++;
}
printf("Total digits is: %d",count);
return 0;
}
Sample output:
Enter a number: 23
Total digits is: 2
4. C code to count the total number of digit using
for loop
#include<stdio.h>
int main(){
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(;num!=0;num=num/10)
count++;
printf("Total digits is: %d",count);
return 0;
}
Sample output:
Enter a number: 456
Total digits is: 3
5. Simple program of c find the largest number
#include<stdio.h>
int main(){
int n,num,i;
int big;
printf("Enter the values of n: ");
scanf("%d",&n);
4
printf("Number %d",1);
scanf("%d",&big);
for(i=2;i<=n;i++){
printf("Number %d: ",i);
scanf("%d",&num);
if(big<num)
big=num;
}
printf("Largest number is: %d",big);
return 0;
}
Sample Output:
Enter the values of n:
Number 1: 12
Number 2: 32
Number 3: 35
Largest number is: 35
6. C program to calculate sum of digits
#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
return 0;
}
Sample output:
Enter a number: 123
Sum of digits of number: 6
5
7. Sum of digits of a number in c using for loop
#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
for(;num!=0;num=num/10){
r=num%10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
return 0;
}
8. Sum of digits in c using recursion
#include<stdio.h>
int getSum(int);
int main(){
int num,sum;
printf("Enter a number: ");
scanf("%d",&num);
sum = getSum(num);
printf("Sum of digits of number: %d",sum);
return 0;
}
int getSum(int num){
static int sum =0,r;
if(num!=0){
r=num%10;
sum=sum+r;
getSum(num/10);
}
6
return sum;
}
Sample output:
Enter a number: 45
Sum of digits of number: 9
9.Write a c program to find out L.C.M. of two
numbers.
Definition of LCM (Least common multiple):
LCM of two integers is a smallest positive integer
which is multiple of both integers that it is divisible
by the both of the numbers.
For example: LCM of two integers 2 and 5 is 10 since 10
is the smallest positive numbers which is divisible by
both 2 and 5.
#include<stdio.h>
int main(){
int n1,n2,x,y;
printf("nEnter two numbers:");
scanf("%d %d",&n1,&n2);
x=n1,y=n2;
while(n1!=n2){
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("L.C.M=%d",x*y/n1);
return 0;
}
7
10. Write a c program to find out the sum of
infinite G.P. series
Definition of geometric progression (G.P.):
A series of numbers in which ratio of any two
consecutive numbers is always a same number that is
constant. This constant is called as common ratio.
Example of G.P. series:
2 4 8 16 32 64
Here common difference is 2 since ratio any two
consecutive numbers for example 32 / 16 or 64/32 is
2.
Sum of G.P. series:Sn =a(1–rn+1
)/(1-r)
Tn term of G.P. series:Tn = arn-1
Sum of infinite G.P. series:
Sn = a/(1-r) if 1 > r
= a/(r-1) if r > 1
#include<stdio.h>
int main(){
float a,r;
float sum=0;
printf("Enter the first number of the G.P. series:
");
scanf("%f",&a);
printf("Enter the common ratio of G.P. series: ");
scanf("%f",&r);
if(1 > r)
sum = a/(1-r);
else
sum = a/(r-1);
printf("nSum of the infinite G.P. series:
%f",sum);
return 0;
}
8
Sample output:
Enter the first number of the G.P. series: 1
Enter the common ratio of G.P. series: .5
Sum of the infinite G.P. series: 2.000000
Enter the first number of the G.P. series: 5
Enter the common ratio of G.P. series: 2
Sum of the infinite G.P. series: 5.000000

More Related Content

What's hot

What's hot (20)

88 c-programs
88 c-programs88 c-programs
88 c-programs
 
program in c
program in cprogram in c
program in c
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
week-1x
week-1xweek-1x
week-1x
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Prim
PrimPrim
Prim
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
C Programming
C ProgrammingC Programming
C Programming
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
week-10x
week-10xweek-10x
week-10x
 
week-11x
week-11xweek-11x
week-11x
 
Najmul
Najmul  Najmul
Najmul
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
C program to add n numbers
C program to add n numbers C program to add n numbers
C program to add n numbers
 

Similar to Progr3

Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 

Similar to Progr3 (20)

C lab
C labC lab
C lab
 
C programs
C programsC programs
C programs
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 
C file
C fileC file
C file
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
Progr2
Progr2Progr2
Progr2
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
C-programs
C-programsC-programs
C-programs
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C important questions
C important questionsC important questions
C important questions
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab excellent
C lab excellentC lab excellent
C lab excellent
 
C and Data Structures Lab Solutions
C and Data Structures Lab SolutionsC and Data Structures Lab Solutions
C and Data Structures Lab Solutions
 
C and Data Structures
C and Data Structures C and Data Structures
C and Data Structures
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 

More from SANTOSH RATH

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management system
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
SANTOSH RATH
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management system
SANTOSH RATH
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TC
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
SANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
SANTOSH RATH
 
Oops model question
Oops model questionOops model question
Oops model question
SANTOSH RATH
 
System programming note
System programming noteSystem programming note
System programming note
SANTOSH RATH
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
SANTOSH RATH
 

More from SANTOSH RATH (20)

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management system
 
Lesson plan proforma progrmming in c
Lesson plan proforma progrmming in cLesson plan proforma progrmming in c
Lesson plan proforma progrmming in c
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
 
2011dbms
2011dbms2011dbms
2011dbms
 
2006dbms
2006dbms2006dbms
2006dbms
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management system
 
Rdbms2010
Rdbms2010Rdbms2010
Rdbms2010
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TC
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Oops model question
Oops model questionOops model question
Oops model question
 
System programming note
System programming noteSystem programming note
System programming note
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
Os notes
Os notesOs notes
Os notes
 
OS ASSIGNMENT 2
OS ASSIGNMENT 2OS ASSIGNMENT 2
OS ASSIGNMENT 2
 
OS ASSIGNMENT-1
OS ASSIGNMENT-1OS ASSIGNMENT-1
OS ASSIGNMENT-1
 
OS ASSIGNMENT 3
OS ASSIGNMENT 3OS ASSIGNMENT 3
OS ASSIGNMENT 3
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Progr3

  • 1. 1 1. Write a c program to swap two numbers. void main() { int a,b,c; clrscr(); printf("n Enter two no "); scanf("%d%d",&a,&b); printf("n Before Swaping value of a and b %d %d",a,b); c=a; a=b; b=c; printf("n After Swaping value of a and b %d %d",a,b); getch(); } 2. Write a c program to swap two numbers without using third variable. #include<stdio.h> #include<conio.h> int main() { int a=5,b=10; //process one a=b+a; b=a-b; a=a-b; printf("a= %d b= %d",a,b); return 0; getch(); } 3. Write a c program to swap two numbers without using third variable. #include<stdio.h> #include<conio.h> int main() { int a=5,b=10; //process one a=b+a;
  • 2. 2 b=a-b; a=a-b; printf("a= %d b= %d",a,b); return 0; getch(); } 1. How to calculate power of a number in c #include<stdio.h> int main(){ int pow,num,i=1; long int sum=1; printf("nEnter a number: "); scanf("%d",&num); printf("nEnter power: "); scanf("%d",&pow); while(i<=pow){ sum=sum*num; i++; } printf("n%d to the power %d is: %ld",num,pow,sum); return 0; } 2. Code for swapping in c #include<stdio.h> int main(){ int a,b,temp; printf("Enter any two integers: "); scanf("%d%d",&a,&b); printf("Before swapping: a = %d, b=%d",a,b); temp= a; a=b; b=a; printf("nAfter swapping: a = %d, b=%d",a,b); return 0; }
  • 3. 3 3. Count the number of digits in c #include<stdio.h> int main(){ int num,count=0; printf("Enter a number: "); scanf("%d",&num); while(num){ num=num/10; count++; } printf("Total digits is: %d",count); return 0; } Sample output: Enter a number: 23 Total digits is: 2 4. C code to count the total number of digit using for loop #include<stdio.h> int main(){ int num,count=0; printf("Enter a number: "); scanf("%d",&num); for(;num!=0;num=num/10) count++; printf("Total digits is: %d",count); return 0; } Sample output: Enter a number: 456 Total digits is: 3 5. Simple program of c find the largest number #include<stdio.h> int main(){ int n,num,i; int big; printf("Enter the values of n: "); scanf("%d",&n);
  • 4. 4 printf("Number %d",1); scanf("%d",&big); for(i=2;i<=n;i++){ printf("Number %d: ",i); scanf("%d",&num); if(big<num) big=num; } printf("Largest number is: %d",big); return 0; } Sample Output: Enter the values of n: Number 1: 12 Number 2: 32 Number 3: 35 Largest number is: 35 6. C program to calculate sum of digits #include<stdio.h> int main(){ int num,sum=0,r; printf("Enter a number: "); scanf("%d",&num); while(num){ r=num%10; num=num/10; sum=sum+r; } printf("Sum of digits of number: %d",sum); return 0; } Sample output: Enter a number: 123 Sum of digits of number: 6
  • 5. 5 7. Sum of digits of a number in c using for loop #include<stdio.h> int main(){ int num,sum=0,r; printf("Enter a number: "); scanf("%d",&num); for(;num!=0;num=num/10){ r=num%10; sum=sum+r; } printf("Sum of digits of number: %d",sum); return 0; } 8. Sum of digits in c using recursion #include<stdio.h> int getSum(int); int main(){ int num,sum; printf("Enter a number: "); scanf("%d",&num); sum = getSum(num); printf("Sum of digits of number: %d",sum); return 0; } int getSum(int num){ static int sum =0,r; if(num!=0){ r=num%10; sum=sum+r; getSum(num/10); }
  • 6. 6 return sum; } Sample output: Enter a number: 45 Sum of digits of number: 9 9.Write a c program to find out L.C.M. of two numbers. Definition of LCM (Least common multiple): LCM of two integers is a smallest positive integer which is multiple of both integers that it is divisible by the both of the numbers. For example: LCM of two integers 2 and 5 is 10 since 10 is the smallest positive numbers which is divisible by both 2 and 5. #include<stdio.h> int main(){ int n1,n2,x,y; printf("nEnter two numbers:"); scanf("%d %d",&n1,&n2); x=n1,y=n2; while(n1!=n2){ if(n1>n2) n1=n1-n2; else n2=n2-n1; } printf("L.C.M=%d",x*y/n1); return 0; }
  • 7. 7 10. Write a c program to find out the sum of infinite G.P. series Definition of geometric progression (G.P.): A series of numbers in which ratio of any two consecutive numbers is always a same number that is constant. This constant is called as common ratio. Example of G.P. series: 2 4 8 16 32 64 Here common difference is 2 since ratio any two consecutive numbers for example 32 / 16 or 64/32 is 2. Sum of G.P. series:Sn =a(1–rn+1 )/(1-r) Tn term of G.P. series:Tn = arn-1 Sum of infinite G.P. series: Sn = a/(1-r) if 1 > r = a/(r-1) if r > 1 #include<stdio.h> int main(){ float a,r; float sum=0; printf("Enter the first number of the G.P. series: "); scanf("%f",&a); printf("Enter the common ratio of G.P. series: "); scanf("%f",&r); if(1 > r) sum = a/(1-r); else sum = a/(r-1); printf("nSum of the infinite G.P. series: %f",sum); return 0; }
  • 8. 8 Sample output: Enter the first number of the G.P. series: 1 Enter the common ratio of G.P. series: .5 Sum of the infinite G.P. series: 2.000000 Enter the first number of the G.P. series: 5 Enter the common ratio of G.P. series: 2 Sum of the infinite G.P. series: 5.000000