Popular Posts

38.Write a program to show the sum of even numbers by using pointers.

38.Write a program to show the sum of even numbers by using pointers.

#include
#include
int main()
{
clrscr();
int numbers[50],*ptr;
int n,i;
cout<<"\nEnter the count\n"; cin>>n;
cout<<"\Enter the numbers one by one\n"; for(i=0;i>numbers[i];
ptr=numbers;
int sum=0;
for(i=0;i {
if(*ptr%2==0)
sum=sum+*ptr;
ptr++;
}
cout<<"\n\nSum of even numbers: "< getch();
return 0;
}

Output:

Enter the count
5
Enter the numbers one by one
10
16
23
45
34


Sum of even numbers: 60




1 comment:

Rick Peterson said...

Great work! I love your post and thank you so much for the codes. It's really very helpful and you are so experienced in programming specifically in C++ language.