Computer Programming Learning Part-07||Week-07||C++ program to add even and odd numbers from seven integer type numbers.
Steemian Friends,
Today, I will write my computer programming learning part 07. Today, I will show you how to write a C++ program to extract even and odd numbers from seven integer-type numbers separately. Hopefully, everyone will benefit from the program I wrote.
Design By Canva
First I write the C++ program to find the sum of even and odd numbers from seven numbers on a white paper. Writing on white paper and typing on my computer is convenient. I can see if there is a mistake in the program.
Then I turn on the computer and open the Code blocks software. Then go to File and click on Empty File to open the program writing compiler. It is shown as a red block in the image below.
Then I first declare the header file and main function of the C++ program which is done at the beginning of writing every C++ program. Below I have declared the header file and main function.
#include<stdio.h>
int main()
{
Then I declare the array for seven numbers of integer type and write a program to declare seven numbers as even and zero as odd. Then declare a variable called i. Then through the for loop, I declare the value of i as zero by checking one by one with the numbers kept in the seven arrays. Below is an example of declaring an integer number and using a for loop.
int a[7], i, even_sum = 0, odd_sum=0;
for (i= 0; i<7; i++)
{
scanf ("%d", & a [i]);
}
printf("values of Array : ");
for (i= 0; i<7; i++)
{
printf(" %d",a [i]);
Then I will write the program to extract even and odd numbers from seven numbers and add them. First I will divide a number by two using the if condition to get the even number. If it is even then add to the value of variable i. In this way, by comparing with seven numbers, the even numbers will be taken out and the sum output will be seen. It is shown in the program form below.
if (a [i] %2 == 0)
even_sum = even_sum + a [i];
Then I add the odd numbers using the else condition and display them as output. It is shown by the following program.
else
odd_sum = odd_sum + a [i];
}
Then, I will write the following program to output the sum of even and odd numbers. Then I complete the program with return0.
printf("\nsum of values : %d\n", odd_sum);
printf("\nsum of even values : %d\n", even_sum);
return0;
}
Then I read and checked the whole program once. Then I click the Run button to run the program. I'm very happy that my program didn't show errors in writing.
Then I see a black blank page to view the output. Here I input seven numbers. Then I see the sum of even and odd numbers separately. As an example in the image below, the output is shown as a red block.
I am slowly adding small program parts and moving towards the big program. I will show some projects later with the C++ program.
Link to my previous post:
Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1808802414587490568?t=Dm42tk6jbScNaabHij39VA&s=19
Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.