print a list of integers from 1 to N that are both divisible by 2 and 3.and after producing the list, count the numbers of integers found.
whatz this dude....it is so simple...u could have tried it... Code: ...................... ...................... ..................... if (n%2==0 && n%3==0) consider the number; increase the counter; else do nothing; .................... .................... ....................
1.first of all take number from the user 2.then run a loop from 1 to user number 3.then inside loop write the code of if statement that if the remainder of the running loop by 2 and 3 are zero then take the number and add in sum integer otherwise step forward 4.finally print the sum
int sum,i,n; cin>>n; sum=0; for(i=1;i<=n;i++) if(i%2==0 && i%3==0) { cout<<i; sum=sum+i; } end of for loop cout<<"sum="sum; end of program run this one then reply
Code: #include "stdafx.h" #include "iostream" #include "stdlib.h" #include "conio.h" using namespace std; void main() { int a; static int m=0; cout<<"input <n> (integer): "; cin>>a; cout<<"\n"; for(int i=1;i<(a+1);i++){ if(i%3==0){ if(i%2==0){ cout<<i<<" "; m=m+1; } } } cout<<"\n number of them= "<<m; cout<<"\n program by AHA"; getch(); } good luck
Code: #include <iostream> using namespace std; int main() { int n; cout<<"Please Enter the maximum Limit(N)\n"; cin>>n; int count=0; for(int i=1;i<=n;++i) { if(i%2==0&&i%3==0) { count++; cout<<i<<" "; } } cout<<"\n\nThe number of integers found is "<<count; return 0; }