52 : C Program to Display 1st 10 natural numbers and their sum

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



This program displays 1st 10 natural numbers (i.e. 1 2 3 4 5 6 7 8 9 10) on screen and calculates it sum. This programs takes no input from user.



Variables :

i : Datatype int : Used in for loop condition.

sum : Datatype int : To hold the sum of 1st 10 natural numbers. Should be initialized to zero








/*
 * 1000+ C programs + tutorials
 *
 * 
 * 52_display_1st_10_natural_numbers_and_their_sum.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include 
//#include <conio.h>

void main() {


//    clrscr();

    int i;
    int sum = 0;

	printf("C Program to Display 1st 10 natural numbers and their sum :  ");
  
  printf("\n\n 1st 10 natural numbers : ");
    
    for(i = 1 ; i <= 10 ; i++) {
    sum = sum + i;
       printf("%d  ",i); 
        
    }
    printf("\n\n Sum of 1st 10 natural numbers : %d  ",sum); 

 

//	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.