Question

Write a C program to add and subtract any two given integer numbers using pointers

1- Write a C program to add and subtract any two given integer numbers using pointers.  

2- Write a C program to find the factorial using a function and pointers.  

3- Write a C program to find the square of an Integer number using a function and pointers.  

4- Write a C program to find the area and perimeter of a rectangle using a function and pointers.  

5- Write a C program to find the larger of two integers numbers using a function returning pointer.

5 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Following is the required code :

#include

int add( int* a, int* b ){
   return (*a)+(*b);  
}

int sub( int* a, int* b ){
   return (*a)-(*b);
}

int factorial( int* n ){
   int i = 1;
   int result = 1;
   for( i = 1; i <= (*n); i++ ){
       result = result*i;
   }
   return result;
}

int square( int* a ){
   return (*a)*(*a);
}

int perimeter( int* a, int* b ){
   return 2*(*a + *b);
}

int area( int* a, int* b ){
   return (*a)*(*b);
}

int larger( int* a, int* b ){
   if( (*a) < (*b) ){
       return *b;
   }
   return *a;
}

int main(){
   int a = 2;
   int b = 3;
   int c = add( &a , &b );
   printf("%d\n",c);
   c = sub( &a , &b );
   printf("%d\n",c);
   c = factorial( &b );
   printf("%d\n",c);
   c = square( &b );
   printf("%d\n",c);


   c = perimeter( &a , &b );
   printf("%d\n",c);
   c = area( &a , &b );
   printf("%d\n",c);
   c = larger( &a , &b );
   printf("%d\n",c);

}

Add a comment
Answer #2
#include #define MAX_SIZE 100 // Maximum string size int main() { char str[MAX_SIZE]; int i; /* Input string from user */ printf("Enter your text : "); gets(str); for(i=0; str[i]!='\0'; i++) { /* * If current character is lowercase alphabet then * convert it to uppercase. */ if(str[i]>='a' && str[i]<='z') { str[i] = str[i] - 32; } } printf("Uppercase string : %s",str); return 0; }
Add a comment
Know the answer?
Add Answer to:
Write a C program to add and subtract any two given integer numbers using pointers
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program requesting the user to input two integer numbers and then requesting the...

    Write a C program requesting the user to input two integer numbers and then requesting the user to either add, subtract, or multiply the two numbers (choose 0 to add, 1 to subtract, or 2 to multiply. Declares three separate functions for these choices to come after main(). Program needs to use a pointer to these three functions to perform the requested action. Must print to output.

  • 1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default...

    1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default value 1) -width, an integer (default value 1) Provide the following member functions: -default constructor -constructor that takes parameters used to initialize the data -get/set function for each attribute -a function perimeter that returns the perimeter of the rectangle -a function area that returns the area of the rectangle b. Write a program that uses the class Rectangle to create two rectangle objects with...

  • The program must be in C# syntax. Write the definition for a generic class called Rectangle...

    The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that...

  • The program must be in C# syntax. Write the definition for a generic class called Rectangle...

    The program must be in C# syntax. Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that...

  • C programming. 1.Create a program that does the following - Creates three pointers, a character pointer...

    C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...

  • 3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...

    3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Your program must, at least, contain a function to read and store a number into an...

  • Write a program to reverse an integer number by using a function called reverse. The program...

    Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...

  • PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which...

    PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...

  • Write the full C program which implements the operations given below using pointers. • Define an...

    Write the full C program which implements the operations given below using pointers. • Define an array of integers (x array). • The size of the array will be 100. • x values will be randomly determined between 1 and 20. • Set the seed of the random number generator to the system time. • Define the external function => y = x2 + 3x + 5 • Calculate and save the results (y values) of the function to another...

  • Question 16 (4 points) Write a complete C program that declares four variables of type integer...

    Question 16 (4 points) Write a complete C program that declares four variables of type integer (i.e integer variables) and four variables of type pointer to integer (i.e. integer pointers). Assign the addresses into the pointers. Using the indirection operator with a pointer, assign the values 1, 2, 3, and 4 into the four integers. (Use the indirection operator with the pointers to write the integer values.) Your program should write the addresses and values of all eight variables to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT