how can i make a program that counts a number multiple by two?

create a for loop and increment the loop counter by two -- inside he loop call printf() to display the value of the loop counter.

Or maybe I misunderstood the question.

get a number from the keyboard
multiply it by 2
call printf() to display the result

Edited 6 Years Ago by Ancient Dragon: n/a

/*
Name : Praveen Kr.
E-mail: [email]prvnkmr449@gmail.com[/email]
Mobile no.:+918808130075

please reply if my post is help for u or if any problem on c ask me on my email.
*/

#include<conio.h>
#include<stdio.h>

void main()
{
int num[]={12,15,61,50,65};
int count=0,i;
clrscr();

for(i=0;i<sizeof(num)/2;i++)
{
if(num[i]%2==0)
    {
    count++;
    }
}
printf("\n\tTotal number of multiple by two is : %d",count);
getch();
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

#include<iostream.h>

int main()
{
    int start,end;
    cout<<"Enter the range by space :";
    cin>>start>>end;
    int count=0;
    while(start<=end)
    {
                     if(start%2==0)
                     count++;
                     start++;
                     }
    cout<<endl<<"Total number of multiple by two is :"<<count<<endl;
    system("PAUSE");
    return 0;
}

>>for(i=0;i<sizeof(num)/2;i++)

Wong. You fail the test. sizeof(int) may or may not be 2, depending on your compiler.

Edited 6 Years Ago by Ancient Dragon: n/a

Sorry for that you can use this

for(i=0;i<sizeof(num)/sizeof(int);i++)

instead of

for(i=0;i<sizeof(num)/2;i++)

now it will work at any computer sorry for not considering this fact.

This article has been dead for over six months. Start a new discussion instead.