Write an C programor C program Write an iterative algorithm

Write an C++ program(or C program):

Write an iterative algorithm that runs until a given condition is met to approximate the Nth root of a given value. You may use loops to ensure the application runs until the user explicitly ends the program.

Error checking: Your program should print a separate error mesage for each of the following conditions: - the user enters improperly formatted input values - the value of A is negative. - the value of n is less than 2.   

Solution

#include<stdio.h>

#include <math.h>

double root1(int,int);

int main()
{
int n;
int num1;
double root;
printf(\"Enter a number greater then 1: \");
scanf(\"%d\",&num1);
if(num1>1)
{
printf(\"Enter the value for \'n\'(the root to be calculated): \");
scanf(\"%d\",&n);
root = root1(num1,n);
printf(\"%d th Root of %d is %f\ \ \", n,num1,root);
}
else
printf(\"Wrong entry\");
return 0;
}

double root1(int a, int b)
{
int j;
double i,k=1;
double incre = 0.01;

for(i=1; i<=a; i = i+incre)
{
for(j=0;j<b;j++)
{
k=k*i;
}
if(a<k)
{
return(i-incre);
break;
}
else
k=1;
}
}

Write an C++ program(or C program): Write an iterative algorithm that runs until a given condition is met to approximate the Nth root of a given value. You may

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site