C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs

Thursday, December 12, 2013

Program Sum of Numbers 1 To N



/*
Write a C++ Program to display and sum of All numbers from
1 to n (the entered positive number)by FOR Loop

For Free C++ Programming Techniques (Example Programs), visit
Www.EasyCppProgramming.Blogspot.Com

and For Good Notes
Visit   Www.ForFreeEducation.Blogspot.Com
*/
#include<iostream.h>

#include<conio.h>

void main()
{

  clrscr();

  int number, counter;
  long sum = 0;
  cout<<"\n Enter a positive number = ";

  cin>>number;

  cout<<"\n\n ----------- Results ------------";

  cout<<"\n\n All Numbers between \n 1 to n(entered positive number)\n by For Loop ";

  for (counter = 1; counter <= number; counter++)
           {
           cout<<"\n \t"<<counter;
           sum = sum + counter;
           }
  cout<<"\n\n The Sum of All Numbers between \n 1 to n(entered positive number)\n by For Loop ="<<sum;

  getch();

}
Share:

0 comments:

Post a Comment

We Love To Hear From You!

EasyCPPprogramming.blogspotcom

Blog Archive

Labels