Multiples of 2 and 3 || for loop || C++
In this, we are going to see for loop, the program is based on for loop which basically, finds the multiples of 2 and 3 from 1 to 50.

The code given below can be used for TURBO C++ Compiler:-

    #include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
	int i;
	cout<<"Numbers between 1 to 50 that are divisible by 2 and 3 are \n";
	for(i=1;i<=50;i++)
	{
		if (i % 2 ==0 and i %3== 0)
		{
			cout<<i<<endl;
		}
	}
	getch();
}
    
    

The code given below can be used for g++/gcc Compiler:-

    #include<iostream>
using namespace std;

int main()
{
	int i;
	cout<<"Numbers between 1 to 50 that are divisible by 2 and 3 are \n";
	for(i=1;i<=50;i++)
	{
		if (i % 2 ==0 and i %3== 0)
		{
			cout<<i<<endl;
		}
	}
	return 0;
}
    
    

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post