68 : C Program to display sum of series 1 + 1/2 + 1/3 + 1/4 + .... + 1/n

Check out the complete list of c-programs : C Program List    





This program calculates sum of series : 1 + 1/2 + 1/3 + 1/4 + .... + 1/n, where n is the number that user enters.

Logic :










/*
 * 1000+ C programs + tutorials
 *
 * 
 * 68_c_program_to_print_sum_of_series 1 + 1/2 + 1/3 + 1/4 + ... + 1/n .c
 *  
 *  
 *
 *  Created on: Oct 25, 2014
 *  Author: Code2care.org
 */

#include 
//#include 

void main() {


//clrscr();

int i,n;
int sum_of_series = 0;
 
 
   printf("\nC Program to print sum of series 1 + 1/2 + 1/3 + 1/4 + .... + 1/n : \n\n ");
 
   printf("Enter the number n : ");
   scanf("%d",&n);
   
   printf("1 + ");
   for ( i = 1 ; i <= n ; i++ )
   {
      sum_of_series = sum_of_series + i;
      if(n != i)
        printf("1/%d  + ", i);
      else
        printf("1/%d",i);
     
   }
   printf(" = 1/%d",sum_of_series);
   

 //    getch(); 

}










The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.