Computer Programming Learning Part-07||Week-07||C++ program to add even and odd numbers from seven integer type numbers.

in Steem4Professionals9 days ago

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.

Programming Learning Part 07.png
Design By Canva


Step01:

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.

IMG20240704145443.jpg

IMG20240704151345.jpg


Step02:

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.

c-10.png

c-11.png

c-12.png


Step03:

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()
{


Step04:

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]);


Step05:

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];


Step06:

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];
}


Step07:

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;
}


Step08:

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.

c-13.png

c-14.png


Step09:

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.

c-15.png

c-16.png

I am slowly adding small program parts and moving towards the big program. I will show some projects later with the C++ program.

Blue line.png

Link to my previous post:

Part-01

Part-02

Part-03

Part-04

Part-05

Part-06

Blue line.png

Steemit.com.png

image.png

Sort:  
Loading...

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(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.

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 58613.96
ETH 3153.58
USDT 1.00
SBD 2.43