Blogger templates

Pages

Tuesday, 8 May 2012

C Program: Calculate the Sum of all Odd numbers between 1 to 50 by using do-while Statement

odd number sum

Statement of C program: Prints the Sum of all Odd integers between 1 to 50 :

#include<stdio.h>
#include<conio.h>

void main()
{
int odnum , sum=0;                                 // odnum Stands for Odd Number
odnum=1;


clrscr();
do
{
sum=sum+odnum;                              // It is also written as sum+=odnum
odnum=odnum+2;                              // It is also written as odnum+=2
}while(odnum<=50);
printf(" Sum=%d\n" , sum);
}                                                    /* End of main() */
                                                 
Output:
 Sum=625



0 comments:

Post a Comment