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

Engg.... | 06:55 | | Best Blogger Tips
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



Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

0 comments:

Post a Comment