Write C programs for the following 1. Write a function to ask to user a number o
ID: 3591646 • Letter: W
Question
Write C programs for the following 1. Write a function to ask to user a number of elements, create random decimal numbers ranging between -3 to 4 and write them into file called "data.txt", seperated by commas. Hint: Use a for loop 2 Using structures and typedef discussed in the #101ecture write a program to do complex division between two complex numbers. 1 e z As a demonstration. compute z1z2 wherez,-2.12 + 1.21 i and z2-2.8 + 7.81. The following program computes the product of two complex numbers So you may want to write a program like #include include typedef struct (float Real; float Im;] Complex; typedef struct (float Real; float Im; Complex; Complex ComplexMultiply(Complex 21, Complex 22) Complex ComplexDivide(Complex z1, Complex z2) Complex Z; Complex Z; z.Real -/*your own code Z.Im *your own code* return z; z 1 . Real*22 . Im Z; 21 . 1m*22 . Real ; 2. Im = return + int main() int main() Complex z1, z2, z; Complex 21,z2,z; :1-Real-0.25; z1.1m=-3.1412; z2-Real-0.98; z2.1m=1.655; z=ComplexMultiply(zl,22); z1.Real--0.8; z1.Im-2.4; z2.Real-3.1; Z2.Im--5.6; /*Your Own code to computer z1/z2 here / by 7:04 PM printf("The product of z2 %f %f 1. ", z.Real, z.1m); Li 10/13/2017 z1 * + return printf(":1 divided z2 is %f + %f 1 . n", z.Real, z.In); return eExplanation / Answer
1.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rand_int_in_range(int lower, int upper)
{
return((rand() % (upper-lower+1)) + lower);
}
int main() {
int n;
printf("Enter number of elements: ");
scanf("%d", &n);
int i;
FILE *fp;
fp = fopen("data.txt", "w");
for (i = 0; i < n; i++) {
fprintf(fp, "%d ", rand_int_in_range(-3, 4));
}
fclose(fp);
return 0;
}
Sample run
./a.out
Enter number of elements: 10
cat data.txt
4
3
-2
0
-2
4
-1
1
-2
2
As per policy answering first question.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.