English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1)write a program to read in an integerN>2 and determine if N is prime number.
2)y=x^4_5x^2+7x-8 write a program which calculate y for values of x from -4 to 4in steps of 0.2. prite x and itscorresponding y value on diffferent lines.
3)print each two-digit odd number N,N^2,N^3 on different lines. the program should be written so that the column of N is headed by NUMBER, N^2 by SQURE,N^3 by CUBE.

2006-10-28 08:20:26 · 1 answers · asked by kater al nada 2 in Computers & Internet Programming & Design

1 answers

For the first you can do a brute force by finding the remainder of dividing by every number from 2 to N-1

if N ==2 then return true

// Check evens
if N mod 2 == 0 then return false

// Check odds
for i = 3 to N - 1 Step 2
if ( N mod i == 0 ) then return false
return true


For the second

for ( double x = -4; x <= 4; x = x + 0.2 )
{
y = pow( x, 4 ) + 5 * pow( x, 2 ) + 7 * x - 8;
// writing it depends on system and you didn't specify
}

You need to specify system for #3

In C

// print header
printf( "Number Square Cube\n")

// print Line
printf( "%2d %2d %2d\n", N, N * N, N * N * N );

2006-10-29 05:30:06 · answer #1 · answered by Daniel H 5 · 0 0

fedest.com, questions and answers