ALL_NUM

Trial

A file named ALL_NUM contains a series of integer numbers.Code a program to read these numbers and then write all odd numbers to a file to be called ALL_ODD and all even numbers to a file to be called ALL_EVEN.


#include <stdio.h>


int main() {

int num1, num2, sum, difference, product, quotient;

int * ptr_num1, * ptr_num2, * ptr_sum, * ptr_difference, * ptr_product, * ptr_quotient;

// Assign addresses of variables to pointers

ptr_num1 = & num1;

ptr_num2 = & num2;

ptr_sum = & sum;

ptr_difference = & difference;

ptr_product = & product;

ptr_quotient = & quotient;

// Input two numbers

printf("Enter first number: ");

scanf("%d", ptr_num1);

printf("Enter second number: ");

scanf("%d", ptr_num2);

// Print addresses of all variables

printf("\nAddresses of variables:\n");

printf("Address of num1: %p\n", ptr_num1);

printf("Address of num2: %p\n", ptr_num2);

printf("Address of sum: %p\n", ptr_sum);

printf("Address of difference: %p\n", ptr_difference);

printf("Address of product: %p\n", ptr_product);

printf("Address of quotient: %p\n", ptr_quotient);

// Perform arithmetic operations using pointers

* ptr_sum = * ptr_num1 + * ptr_num2;

* ptr_difference = * ptr_num1 - * ptr_num2;

* ptr_product = * ptr_num1 * * ptr_num2;

if ( * ptr_num2 != 0)

*

ptr_quotient = * ptr_num1 / * ptr_num2;

// Print results

printf("\nResults:\n");

printf("Sum: %d\n", * ptr_sum);

printf("Difference: %d\n", * ptr_difference);

printf("Product: %d\n", * ptr_product);

if ( * ptr_num2 != 0)

printf("Quotient: %d\n", * ptr_quotient);

else

printf("Error! Division by zero is not allowed.\n");

return 0;

}

إرسال تعليق