Write a program that will compute the sum of the first n pos

Write a program that will compute the sum of the first n positive odd integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9. Use while loop to implement the project. The program accept integer n from keyboard. Rewrite the program by using the while loop.

Solution

a)))))))))))))

#include <stdio.h>

int main()

{

    int j, num, sum_odd=0;

    printf(\"please enter the number: \");

    scanf(\"%d\", &num)

    for(j=1; j<=num; j=j+2)

    {

        sum_odd += j;

    }

    printf(\"\ sum of odd numbers = %d\",sum_odd);

    return 0;

}

b)))))))))))

#include <stdio.h>

int main()

{

    int j=1, num, sum_odd=0;

    printf(\"Enter the number: \");

    scanf(\"%d\", &num);

while( j<=n)

    {

        sum_odd += j;

j=j+2;

    }

    printf(\"\ Sum_odd = %d\",sum_odd);

    return 0;

}

#include <stdio.h>

int main()

{

    int j, num, sum_odd=0;

    printf(\"please enter the number: \");

    scanf(\"%d\", &num)

    for(j=1; j<=num; j=j+2)

    {

        sum_odd += j;

    }

    printf(\"\ sum of odd numbers = %d\",sum_odd);

    return 0;

}

b)))))))))))

#include <stdio.h>

int main()

{

    int j=1, num, sum_odd=0;

    printf(\"Enter the number: \");

    scanf(\"%d\", &num);

while( j<=n)

    {

        sum_odd += j;

j=j+2;

    }

    printf(\"\ Sum_odd = %d\",sum_odd);

    return 0;

}

 Write a program that will compute the sum of the first n positive odd integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9. Use while loop to
 Write a program that will compute the sum of the first n positive odd integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9. Use while loop to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site