Â
In this, we are going to see for loop, the program is based on for loop which basically, calculates the sum of 1 to 10 natural numbers using for loop.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i, sum = 0;
for (i = 0; i <= 10; i++)
{
sum = sum + i;
}
cout << "Sum of 10 number is : " << sum;
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
int i, sum = 0;
for (i = 0; i <= 10; i++)
{
sum = sum + i;
}
cout << "Sum of 10 number is : " << sum;
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP