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

Recommended Answers

All 5 Replies

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

/*
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();
}
#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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.