Search
 
SCRIPT & CODE EXAMPLE
 

C

code example of sum of the first n odd numbers using for loop

def OddSummation(n):
    total = 0
    for i in range(1,n,2):
        total+=i
    return total
    
    
def main():
    number = int(input("Enter the number: "))
    print("The summation of all the odd numbers between 1 and ",number, " is ",         OddSummation(number))
    
main()
Comment

find sum of all odd numbers from 1 to n using for loop

/**
 * C program to print the sum of all odd numbers from 1 to n
 */

#include <stdio.h>

int main()
{
    int i, n, sum=0;

    /* Input range to find sum of odd numbers */
    printf("Enter upper limit: ");
    scanf("%d", &n);

    /* Find the sum of all odd number */
    for(i=1; i<=n; i+=2)
    {
        sum += i;
    }

    printf("Sum of odd numbers = %d", sum);

    return 0;
}
Comment

summing all Odd Numbers from 1 to N

# Python Program to Calculate Sum of Odd Numbers from 1 to N
 
maximum = int(input(" Please Enter the Maximum Value : "))
Oddtotal = 0

for number in range(1, maximum+1, 2):
    print("{0}".format(number))
    Oddtotal = Oddtotal + number

print("The Sum of Odd Numbers from 1 to {0} = {1}".format(number, Oddtotal))
Comment

PREVIOUS NEXT
Code Example
C :: size of operator in c language 
C :: rust unit test display 
C :: functions in c programming 
C :: size of int in c 
C :: pointer in c 
C :: realloc in c 
C :: how to take input in c 
C :: bp result system 
C :: marquee html code with right 
C :: C Syntax of return statement 
C :: can we use logical operators in switch c 
C :: c code to mips assembly converter online 
C :: como somar em C 
C :: Minimum Distance between words[AMAZON] 
C :: c %d 
C :: winautomation block input not working 
C :: c timespec 
C :: overhead computer science 
C :: c math.h sqrt 
C :: 25802 WARNING: lib not found: _pywrap_tensorflow_internal.pyd dependency of D:Devtoolsminicondalibsite-packages ensorflowpythonclient\_pywrap_tf_session.pyd 
C :: if statement shortcut c 
C :: what is the difference between algorithm and flowchart in c program 
C :: send array to child process c 
C :: search and then change string -- strstr and strcpy 
C :: how to use arry 
C :: c logarithm check if number is base 
C :: in C char to string 
C :: recursion c prime number 
Dart :: list item bottom border in flutter 
Dart :: flutter check if string is number dart 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =