Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write xa program that add up all the odd integer bettuen 20 and 56 and print the result.

0 votes
asked Apr 28, 2018 by anonymous

2 Answers

0 votes
answered Apr 30, 2018 by Tulika mukherjee (140 points)
#include<stdio.h>
void main()
{
    int sum=0,i;
   for(i=20;i<=56;i++)
   {
       if(i%2!=0)
       {
           sum=sum+i;
       }
   }printf("%d",sum);
   
}
0 votes
answered Apr 30, 2018 by phantom (140 points)

constexpr int sum(const int a, const int b)
{
    return (a<=b)? (((a%2!=0)? (a):(0))+sum(a+1,b)):0;
}

int main()
{
    std::cout << sum(20, 56) << std::endl;
    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...