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++ ********