write an algorithm to compute the sum of odd and even upto N.
Answers
Answered by
1
Explanation:
The algorithm as :
Step 1: Start.
Step 2 : Input N.
Step 3 : sume = 0.
Step 4 : sumo = 0.
Step 5 : ctr = 1.
Step 6 : while (ctr < = N). If (ctr mod 2 = 0) sume = sume + ctr else sumo = sumo + ctr.
Step 7: Print “sum of even number is” sume.
Step 8: Print “sum of odd number is” sumo.
Step 9: End
punithapuni7670:
flowchart
Answered by
1
Answer:
The program output is also shown below.
•int i, num, odd_sum = 0, even_sum = 0;
•printf("Enter the value of num\n");
•scanf("%d", &num);
•for (i = 1; i <= num; i++)
•if (i % 2 == 0)
•even_sum = even_sum + i;
•odd_sum = odd_sum + i;
•printf("Sum of all odd numbers = %d\n", odd_sum)
Similar questions
Business Studies,
2 months ago
English,
2 months ago
English,
4 months ago
Math,
10 months ago
Economy,
10 months ago