Write a program   that calculates the sum of Odd integers from 1 to an integer N entered by the user.   Example   N=8   Sum = 1 +3+5+7= 16


******** In Algorithm ********

Algorithm Variables i,N, sum : integers Begin sum ← 0 write("Enter an integer :") read(N) for i from 1 to N if ( i % 2 ≠ 0) then sum ← sum + i next next write ("Sum = " , sum) End Result ==> Enter an integer : 12 Sum = 36


******** In C ********

#include<stdio.h> int main(){ int i , N, sum=0; printf("Enter an integer :"); scanf("%d",&N); for(i=1; i<= N;i++){ if ( i%2!=0 ) sum = sum+i; } printf(" the sum = %d", sum); return 0; }


******** In C++ ********

#include <iostream> using namespace std; int main(){ int i,N, sum=0; cout<<"Enter an integer :"; cin>>N; for(i=1; i<= N;i++){ if ( i%2!=0 ) sum = sum + i; } cout<<" the sum = "<<sum; return 0; }