#define minl (x, y) ( (x < y) ? x : y) #define min 10 #include <stdio.h> int min2(int x, int y) { if (x < y) return x; else return y; } main() { int a, b; scanf("%d %d", &a, &b); if (b < min) printf("input out of range\n"); else { a = minl(a, b++); printf("a = %d, b %d\n", a, b); a = min2(a, b++); printf("a = %d, b %d\n", a, b); } } ------------------------- 1 Give the exact C code of the statement "a = min1(a, b + + ) ; " after macro processing. 2. Give the exact C code of the statement "a = min2 (a, b++) ; "after macro processing. 3 Give the exact C code of the statement "if ( b < min) " after macro processing. 4 Assume 60 and -30 are entered as inputs. What is the exact output of the program? 5 Assume 50 and 30 are entered as inputs. What is the exact output of the program?
1. a= min1(a,b++);
Macro min1 is:
min1(x,y) ((x<y) x:y)
After macro processing the code will be:
a= ((a<b++) a:b++);
2. a= min2(a,b++)
min2 is a function,
After macro processing the exact C code:
a= { if ( a< b ) return a;
else
return b;
}
b++;
3. Exact C code after macro processing of
if ( b < min) is:
if(b < 10)
4. 60 for a and -30 for b gives output as:
input out of range
This is because, the value of b (-30) is less than value of min(10). Hence the above statement is printed out.
5. 50 for a and 30 for b gives output as:
a = 31, b 32
a = 32, b 33
The first statement is from macro expansion:
Thus b value is incremented twice once while comparing and another while assigning to a. Thus the above values are resulted. The second line is from the function, here the increment is done only once that is done(after returning from function min2).
I am told to find the median of random inputs using if statements in C #include <stdio.h> #include <stdlib.h> int main() { double a, b, c, d; scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &c); if (a<b && b<c) d = b; printf("%.0f\n", d); else if (b<a && a<c) d = a; printf("%.0f\n", d); else d = c; printf("%.0f\n", d); return 0; } That is my code, I keep getting an error for the else if and else saying there is no...
How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...
C program take values to 9 and the second can take values to 12 if (x > 2^3) printf("d", x); Int s-e; 21. LOST) Write a statement that declare an array of doubles with two indices, such that the first index can 22 (LOL) The following code will print out: 23. (L02.) The following code will print out: PART 2 Fill in the banks questions 3 marts x + 5; else x -- 2; char "stri - "abcd"; char str2[]...
#include <stdio.h> #include string.h #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE 35.00 #define MV4_PRICE 18.49 #define DISCOUNT 0.05 #define DISC_THRES 10 #define SAME_DAY_DELIVERY = 35.0 #define NEXT_DAY_DELIVERY = 20.0 typedef enum{ WRONG, C17, F25, DN3, GG7, MV4} part /*--- Function Prototypes ------------*/ part getPartType ( void ); int getquantity ( void ); int getDeliveryOption ( void ); float calcPriceOfParts( part orderedPart, int quantity ); float calcTotalCarges ( float orderPrice, char...
Need help with these questions in C programming: 9. What is the output of the following code? int X[10]={0}; int N=4; for(int k=0; k<N:k++) X[k] = k*2: printf("%d", X[N/2]; 10. Write a single statement to accomplish each of the following. Assume that each of these statements applies to the same program. a. Write a statement that opens file "oldmast.dat" for reading and assigns the returned file pointer to ofPtr. b. Write a statement that opens file "trans.dat" for writing and...
write solution to the program above in C please and thank you. Output all combinations of character variables a, b, and c. If a x,b-y, and c z, then the output is Your code will be tested in three different programs, with a, b, c assigned with Χ. 'y', 'z', then with #. 'S. %, then with T, 23 1 #include 3 int main(void) { char a char b; char c; 4. 7 scanf(" scanf(" scanf(" %c %c %c ",...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...
the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...
i'm having trouble making an else statement that will allow the program to add and output the average the valid numbers inputed into the program. Here's my output: Enter Score 1:36 Enter Score 2:-1 Invalid Input Enter Score 2:89.5 Enter Score 3:42 Enter Score 4:66.3 Enter Score 5:93 You entered: 36.000000, 89.500000, 42.000000, 66.300000, 93.000000 Total Score: 362.800000 Average Score: 72.560000 Max Score: 93.000000 Min Score: 36.000000 Here's my code: #include <stdio.h> int main(void) { double score[5]; double min; double...
#include<stdio.h> int main() { int data[10], i, j, temp; printf("Enter 10 random number to sort in ascending order:\n"); for(i = 0; i < 10; i++) scanf("%d", &data[i]); /* Sorting process start */ ****** INSERT YOUR CODE TO COMPLETE THE PROGRAM ****** printf("After sort\n"); for(i = 0; i < 10; i++) printf("%d\n",data[i]); return 0; } Looking for alternative solutions for the program code.