Write a program in C to display the n terms of odd natural number and their sum


program

#include <stdio.h>

#include <conio.h>

void main()

{

    int a, sum = 0;

    printf("enter a value of a: ");

    scanf("%d", &a);

    for (int i = 0; i <= a; i++)

    {

        if (i % 2 != 0)

        {

            sum = sum + i;

            printf("%d ", sum);
        }
    }

    printf("\n%d is the sum", sum);

    getch();
}

OUTPUT 
Enter a value of a: 7
1 4 9 16 
16 is the sum

Follow our page for regular updates.

0 Comments