1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

c++ that print the list of integers

Discussion in 'C++' started by arjen, Sep 29, 2010.

  1. arjen

    arjen New Member

    Joined:
    Sep 29, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    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;
    ....................
    ....................
    ....................
    
     
  3. aftabsharif

    aftabsharif New Member

    Joined:
    Oct 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bahawalpur
    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
     
  4. rafay_07

    rafay_07 New Member

    Joined:
    Oct 17, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    you have to display "counter " out of the loop to display number of integers found
     
  5. aftabsharif

    aftabsharif New Member

    Joined:
    Oct 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bahawalpur
    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
     
  6. AHA1376

    AHA1376 New Member

    Joined:
    Oct 14, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  7. ashken

    ashken New Member

    Joined:
    Oct 22, 2010
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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;
    }
    
    
     

Share This Page