Question

In: Computer Science

#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...

#include <stdio.h>

#include <math.h>

int fun(int);

int main(void)   

{

    int i = 5, x = 3;

    i = fun(x);

    printf("%d\n", i);

    return 0;

}

int fun(int i)

{

     int res = 0;

     res = pow (i , 3.0);

     return ( res);

}

Solutions

Expert Solution

Hi, since there is nothing mentioned as what to do with this code so I'm assuming that you want the output of this code. So for that I'm attaching the snippets of the code and it's output. The output of this code is 27.​​​​​​

The value of x is 3 and that 3 is passed as input when the function fun is called in line 7. Pow function is used to calculate the power. So the power of 3 will be 27 so the value of res will be 27 and that value will be return from the function. And hence that value will be stored in the variable i as the output from the function call. So the printed output will be 27 and not 5 which was the intially defined value of x.


Related Solutions

#include <stdio.h> #include<math.h> int main (void). { int I, j, k, num_elem; double x[20], y[20],z[20]; FILE*infile,...
#include <stdio.h> #include<math.h> int main (void). { int I, j, k, num_elem; double x[20], y[20],z[20]; FILE*infile, *outfile; infile = fopen (“c6_3.IN”, “r”); outfile = fopen (“c6_3.OUT”, “w”); k = fscanf (infile, “%lf %lf”, &x[0], &y[0]); fprintf (outfile,”k= %d\n”,k); fprintf (outfile, “value of EOF = %d\n”, EOF); i =1; while ( fscanf(infile, “%lf %lf”, &x[i], &y[i]) != EOF) i++; num_elem =I; fprintf(outfile,” x[i] y[i] z[i]\n”); For (j=0; j<num_elem; j++) { Z[j] =sqrt(x[j] *x[j] +y[j]*y[j]); fprintf(outfile,”%7.1f %7.1f %7.1f\n”, x[j] , y[j], z[j]);...
Please implement the 5 questions in source code: #include <stdio.h> #include <stdlib.h> #include <math.h> int main(...
Please implement the 5 questions in source code: #include <stdio.h> #include <stdlib.h> #include <math.h> int main( int argc, char* argv[] ) { // Size of vectors int n = 10000; // Input vectors double *restrict a; double *restrict b; // Output vector double *restrict c; // Size, in bytes, of each vector size_t bytes = n*sizeof(double); /* Q1: Allocate memory for vector a (10 points)*/ /* Q2: Allocate memory for vector b (10 points)*/ /* Q3: Allocate memory for vector...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int a,b,c,D,n; double x1,x2; double realPart, imagPart; do { // this set of code blocks prompts a message to the user and then read the integer entered and stores it as an integer printf("Enter a value for a:\n"); scanf("%d",&a); printf("Enter a value for b:\n"); scanf("%d",&b); printf("Enter a value for c:\n"); scanf("%d",&c); printf("You entered the Equation \n"); printf("%dx^2%+dx%+d=0\n",a,b,c); D = b*b - 4*a*c;    if (D<0)...
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t...
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t player1, player2, player3;     pthread_create(&player1, NULL, (void *)race, NULL);     pthread_create(&player2, NULL, (void *)race, NULL);     pthread_create(&player3, NULL, (void *)race, NULL);     pthread_join(player1, NULL);     pthread_join(player2, NULL);     pthread_join(player3, NULL);     printf("Total Number = %d\n", shared);     return 0; } void race(void) {     long i,tmp;     for(i=1; i<=200000; i++) {         tmp = shared;         tmp = tmp + 1;         shared =...
#include <stdio.h> #include <stdlib.h> // required for atoi int main(void) {     int i=0,n,num,filenum[100],pos;     int...
#include <stdio.h> #include <stdlib.h> // required for atoi int main(void) {     int i=0,n,num,filenum[100],pos;     int c;    char line[100]; //declaring string for storing data in the line of text    FILE *fp; // declaring a FILE pointer    fp=fopen("numbers.txt","r"); // open a text file for reading    while(fgets(line, sizeof line, fp)!=NULL) {       // looping until end of the file         filenum[i]=atoi(line); //converting data in the line to integer and storing it into array        i++;    }...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use this for your input */ scanf("%d", &input);    /* This is the only output you need */ printf("%.1lf", average); return 0; } Please write a C coding program (make it simple coding)  that find the average of sequence integer. when user enter integers, once at a time. Also, If the user enters 0 (zero), the code will calculates the average and then prints it, and...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter between 8 to 60 inches: "); scanf("%d",&diameter); // if(diameter>60 || diameter<=8){ // printf("Error! invalid input"); // exit(0); // } // else{ // float radius = diameter/2; // float volume = (4/3)*PI*radius*radius*radius; // printf("%.2f",volume); // } //check through the while loop if it is valid or in valid while(diameter>60 || diameter<=8){ printf("Invalid input Enter again: "); scanf("%d",&diameter); }    //caluclate the volume of sphere float...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck */ for(int i = 0; i < DECK_SIZE; i++) { deck[i] = i + 1; }    /* Get the cut position as an integer input */    /* Verify that the input is valid */    /* Cut the deck */    /* Print the resulting deck with one element on each line */ return 0; } Write a program that "cuts" a...
C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print...
C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print down from 2 to 0 by 0.1 increments\n"); float f = 2.0; while (f != 0) { printf("%0.1f\n",f); f = f - 0.1; } printf("============== Problem #2 =================\n"); printf("This should find that the average is 5.5\n"); int total_score = 55; int total_grades = 10; double avg = total_score/total_grades; printf("Average: %0.2f\n",avg); printf("============== Problem #3 =================\n"); printf("If the population increases by 2.5 people per second, how...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT