max <- 0 for(i in 1:1000){ x1 <- runif(1:10, 1) x2 <- runif(1:10, 1) x3 <- runif(1:10, 1) z <- (exp(x1)+x2)^2 + (3(1-x3)^2) if(z > max) max <- z } print(max) This has to print maximum number between 1 to 10000 and 'z' is the formula. I am getting error "Error: attempt to apply non-function".

Member Avatar
Member Avatar
+0 forum 2

I need to output in four columns. 1) The first will contain n. 2) The second will contain pi(n) 3) The third will contain n/ln(n) 4) The fourth will contain the ration of pi(n) to n/ln(n). #include <stdio.h> #include <string.h> #include <stdint.h> #define MAXN 100000000 /* maximum value of N */ #define P1 1562501 /* = ceil(MAXN/64) */ #define P2 50000000 /* = ceil(MAXN/2) */ #define P3 5000 /* = ceil(ceil(sqrt(MAXN))/2) */ uint32_t sieve[P1]; #define GET(b) ((sieve[(b)>>5]>>((b)&31))&1) void make() { uint32_t i, j, k; memset(sieve, 0, sizeof(sieve)); for (k = 1; k <= P3; k++) if (GET(k)==0) for(j=2*k+1,i=2*k*(k+1);i<P2;i+=j) sieve[i>>5]|=1<<(i&31); } …

Member Avatar
Member Avatar
+0 forum 4

Write a program with subclass InterestAccount and CDAccount. The driver program (Account.java) must perform following transactions: 1) Print the name of your bank and yours at the top. 2) Creat an Intrest Account for "Benjamin Franklin" with PIN of 1234 and a starting balance of $100. 3) Creat a CD Account for "William Shakespeare" with PIN of 4321 and a statring balance of &1000. 4) Do three monthly updates, printing out the amount in each account. 5) Deposit $1000 in the Amazon's accounts. 6) Withdraw $500 from Ebay's accounts. 7) Do at least 10 times or more monthly updates, printing …

Member Avatar
Member Avatar
+0 forum 2

Write a java code, Extend class Fraction by adding methods for the arithmetic operators +, - and /, and the six relational operators (==, !=, <, >, <= and >=). Then compute a menu-driven fraction calculator. Program shoud do all 9 arithmetic operations and 0 to stop. User should first asked for the options 1 to 0 and then asked for first fraction and second fraction. It will keep running until user enter 0 to stop. Fraction class code: import java.util.*; // Scanner import java.io.*; // PrintStream public class Fraction extends Object { private int myNumerator, myDenominator; public Fraction() { …

Member Avatar
Member Avatar
+0 forum 2

C program that extends my.c to take file names as command line arguments. It will read each named file and write the first 10 lines to standard output. If there are no command line arguments, it will read from standard input. If "-" is given as a file name, it will read from standard input. As with the Linux version of head, program should print the file name (or standard input) if there are two or more command line arguments. Use the same format as the Linux version of head. Write a function **void do_file(FILE *infile)** that takes a stream …

Member Avatar
Member Avatar
+0 forum 2

How to convert C++ code to C. Write a program in C that asks a user for the name of a file. The program should display the first 10 lines of the file on the screen (the "head" of the file). If the file has fewer than 10 lines, the entire file should be displayed, with a message indicating the entire file has been displayed. \//Run the program using visual studio 2010 vc++ /** *This program ask the user to enter the name of the text file *and displays the ten lines of the file and if the file having …

Member Avatar
Member Avatar
+0 forum 10

I have problem reading file form command line. I am trying to do " abcd: ./rev < numbers", but it gives me an error: ./rev < numbers Usage : ./rev FILENAME Here is the code: #include <stdio.h> #include <stdlib.h> void reverse(FILE * file) { int fscanf_return_value; char x; /* read a char */ fscanf_return_value = fscanf(file,"%c",&x) ; if(fscanf_return_value == EOF) { //fscanf returns EOF as the END OF FILE return; } reverse(file); //Get the next char //do something with the char e.g. print putchar(x); return; } int main(int argc, char *argv[]) { int i; FILE *fd; if (argc!=2) { printf("Usage …

Member Avatar
Member Avatar
+0 forum 4

I am getting wrong output. My Code is following, in which I have to use function unsigned long powerof2(int n); #include <stdio.h> #include <stdlib.h> #include <math.h> //int powerof2(int n); unsigned long powerof2(int n); int main(void) { printf(" n 2^n\n"); printf("-- ---\n"); for (int n=0; n<65 ;n++) { //printf(" n 2^n\n"); printf("%d %ld\n", n, powerof2(n)); } } unsigned long powerof2(int n) { unsigned long y; for(int j=0;j<65;j++) { if (n == 64) y = 0; else y = 1 << n; } return y; } Output: n 2^n -- --- 0 1 1 2 2 4 3 8 4 16 5 …

Member Avatar
Member Avatar
+0 forum 5

I am trying to print: 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576 21 2097152 22 4194304 23 8388608 24 16777216 25 33554432 26 67108864 27 134217728 28 268435456 29 536870912 30 1073741824 31 -2147483648 32 0 Thsi is my code: #include <stdio.h> #include <stdlib.h> #include <math.h> int powerof2(int n); int main(void) { for (int n=0; n<32 ;n++) { printf("n 2^n\n"); printf("%d %d\n", n, powerof2); } …

Member Avatar
Member Avatar
+0 forum 6

Histo.java import java.util.*; // Scanner import java.io.*; // PrintStream class Histo extends Object { static PrintStream theScreen = new PrintStream(System.out); static Scanner theKeyboard = new Scanner(System.in); public static void main(String args[]) throws FileNotFoundException { final int MAX_SCORES = 5000; // define nameArr as an array of String objects String[] nameArr = new String[MAX_SCORES]; // define scoreArr as an array of double objects double[] scoreArr = new double[MAX_SCORES]; //double[] sorted = new double[MAX_SCORES]; int scores = fillArraysFile( nameArr, scoreArr); //convert the array into one that just contains valid scores scoreArr = DoubleArrayOps.subArray(scoreArr, 0, scores-1); // theScreen.println(Arrays.toString(nameArr)); // DoubleArraysOps.printArray(theScreen, scoreArr); theScreen.print( "\nMean …

Member Avatar
Member Avatar
+0 forum 10

Write a program that (using an array) analyzes student performance on an exam using the information from such a file. The program should input the name of the text file, and then display the worst score, the best score, the average score, the standard deviation, and a histogram -- a bar graph indicating the frequency with which a given score occurred. For example, if three people scored 74, five people scored 75, six people scored 76, no one scored 77 and two people scored 78, then that portion of the histogram should appear as: 74: *** 75: ***** 76: ****** …

Member Avatar
Member Avatar
+0 forum 1

wrong post

Member Avatar
Member Avatar
+0 forum 1

The End.