//program
to print the sum of all odd numbers between 1 to 10 using do while loop
void main()
{
int i=1,sum=0;
clrscr();
do
{
sum=sum+i;
i+=2;
}while(i<=10);
printf("the
sum of all odd numbers between 1 to 10 is %d",sum);
getch();
}
Output
the sum of all odd numbers between 1 to 10 is 25
How would you list the odd numbers in a while loop?
ReplyDeleteIn the following way
Deletemain()
{
int i=1;
while(i<=10)
{
printf("%d\t",i);
i+=2;
}
}