Monday, 3 March 2014

Write a C program to calculate sum of first n odd integers.

#include<stdio.h>

main()
{
    int num,sum=0,i=1;
    printf("\nEnter a number=");
    scanf("%d",&num);
    while(i<=num)
    {       
        sum+=2*i-1;
        i++;
    }   
    printf("\nThe sum =%d",sum);
}

No comments:

Post a Comment