C++ Program to print 1,4,7,10,13… series up to N

/* C++ Program to print 1,4,7,10,13… series up to N */
#include <iostream>
using namespace std;
int main() 
{
	int a;
 	int i;

	cout << "Enter Last Number : ";
 	cin >> a;
 	for(i=0;i<=a;i++)
 	{
 		if(i%3==1)
 		{
 			cout << i <<",";
		}
	 }	
    return 0;
}

Output :
Enter Last Number : 25
1,4,7,10,13,16,19,22,25,



Leave a comment