For the following questions show all of your work It is not
For the following questions, show all of your work. It is not sufficient to provide the answers. For programming questions, please generate screenshots of your code execution, assembly codes, and your analysis/explanation, and submit with your assembly and C code.
Write a C code to compute the summation of all odd numbers between 0 and 20. You have to use for three different kinds of loop. Rewrite your code using goto and label statement as well. Compile and run your code. Generate assembly code and analyze the results.
Solution
I am just providing solution to find sum of odd numbers between 0 to 20 using three different loops
#include<iostream.h>
#include<stdio.h>
1) using for loop
void main()
{ int sum =0;
for(int i=0;i<=20;i++)
{
if( i%2 !=0)
{
sum = sum+i;
}
}
}
2) Using while loop
void main()
{ int sum =0, i=0;
while(i<=20)
{
if( i%2 !=0)
{
sum = sum+i;
}
i++
}
}
3) Using do while loop
void main()
{ int sum =0,i=0;
do{
if( i%2 !=0)
{
sum = sum+i;
}
i++;
}while(i<=20);
}

