C Questions Answers-C Function(PartII)


C Function(PartII)

1. Find any errors in the following function definition:
void myfunction(int x,int y){
  printf("%d",x*y);
  return(x*y);
}
Check answer 2. Find any errors in the following function definition:
int myfunction(int x,y){
    return(x*y);
}
Check answer 3. Find any errors in the following function prototypes:
a.int sum(int x,y);
b.int sum(int x,int y)
c.int sum(int x,void y);
Check answer 4. What would be the output from the following C program when run using 3 4 as input data?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int subtr(int x,int y);
int main(){
  int x,y,res;
  printf("Enter x and y separated by space:");
  scanf("%d %d",&x,&y);
  res=subtr(x,y);
  printf("Result=%d",res);

getch();
return 0;

}

int subtr(int x,int y){
return(x-y);
}
 Check answer 5.What would be the output from the following C program when run using 2 4 1 as input data?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int max3(int x,int y,int z);
int main(){
  int x,y,z,max;
  printf("Enter x, y and z separated by space:");
  scanf("%d %d %d",&x,&y,&z);
  max=max3(x,y,z);
  printf("The max value is %d.",max);

  getch();
  return 0;

}

int max3(int x,int y,int z){
  if(x>y)
     if(x>z) return x;
     else return z;
  else if(y>z) return y;
  else return z;
}
Check answer 6.What would be the output from the following C program when run a.using 3 2 as input data?      b. using 3 -2 as input data?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
double mypower(int base,int pow);
int main(){
  int b,p;
  double res;
  printf("Enter base value and its power separated by space:");
  scanf("%d %d",&b,&p);
  res=mypower(b,p);
  printf("Result=%f",res);

  getch();
  return 0;

}

double mypower(int base,int pow){
  if(pow>=0){ //positive power
    if(pow==0) return 1;
    else if(pow==1) return base;
    else return (base*mypower(base,pow-1));
}
else{ //negative power
  if(pow==-1) return(1/(double)base);
    else return((1/(double)base)*mypower(base,pow+1));
}
}


Check answer


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.