How to write a program that tells the user to enter a and b

How to write a program that tells the user to enter a and b integers and then if a is smaller than or equal to b then calculate the sum using (1.0/a) + (1.0/a+1) + (1.0/a+2).... until (1.0/b), but using if else statements or loops.

Solution

writing a program in c to your query.

#include<stdio.h>

void main()
{
int a, b;

printf(\"Enter A \ \");
scanf(\"%d\",&a);
printf(\"Enter B \ \");
scanf(\"%d\",&b);  

if(a<=b)
{
double total;
for (int i =a;i<=b;i++)
{
total +=(1.0/i);
}
printf(\"Sum of (1.0/a)+..(1.0/b) = %1f\", total);

else
{
printf( \"a is greater than b\");
exit(0);
}


}

How to write a program that tells the user to enter a and b integers and then if a is smaller than or equal to b then calculate the sum using (1.0/a) + (1.0/a+1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site