The program I'd like to design is supposed to read in an integer k, and print out the number of positive integers between 1 and 100,000 (inclusive) which have exactly k divisors. As an example, the number 24 has 8 divisors: 1, 2, 3, 4, 6, 8, 12, and 24.
So far this is what I got
int finddivisor(int *k)
{
int x, j, m;
*k = m;
printf("Enter the target number of divisors:");
scanf("%d", &k);
for (int i = 0; i < 100000; i++)
{
for (int x = 0; x <= i; x++)
{
if (i % x == 0)
{
j++;
}
}
}
printf("There are %d numbers between 0 and 100,000 that have k divisors", j);
}
#include <stdio.h>
int finddivisor(int *k)
{
int i, x, j, m = 0; // m stores numbers that have exactly k divisors
printf("Enter the target number of divisors: "); // read k from
user
scanf("%d", k);
for (i = 1; i <= 100000; i++)
{
x = 0; // x stores number of divisors for each numbers
for (j = 1; j <= i; j++)
{
if (i % j == 0) // if j divides i
{
x++; // increment x by 1
}
}
if (x == *k) // if x equals to k
{
m++; // increment m by 1
}
}
printf("There are %d numbers between 1 and 100,000 that have %d divisors", m , *k); // print the result
return m;
}
int main()
{
int k,d;
d = finddivisor(&k); // calling function
return 0;
}
The program I'd like to design is supposed to read in an integer k, and print...
a) The following program is supposed to convert a binary number to its decimal equivalent. Modify the program so that it does the job.(15 points) b) How would you create the executable file of the program (file name: b2d.c) in Linux? (5 points) #include <stdio.h> int main (void) int binary: printf("Enter a binary number:\n"); scanf("%d", &binary): int nofDigit = 0, remain = binary: while (remain > 0) - remain = remain/10; nofDigit++; int digit, dval = 0, bx = binary:...
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /* */ /* */ /* This program computes average power, average magnitude */ /* and zero crossings from a speech signal. */ #include <stdio.h> #include <math.h> #define MAXIMUM 50 int main(void) { /* Declare variables */ int k=0, npts=30; double speech[MAXIMUM]={0.000000,-0.023438,-0.031250,-0.031250,-0.039063,-0.039063,-0.023438,0.000000,0.023438,0.070313,-0.039063,-0.039063,0.046875,0.101563,0.117188,0.101563,0.070313,0.054688,0.023438,0.000000,-0.031250,-0.039063,-0.070313,-0.070313,-0.070313,-0.070313,-0.062500,-0.046875,-0.039063,-0.031250}; /* Declare the function prototypes */ /* Compute and print statistics. */ printf("\n SPEECH DATA "); print(,,);//complete the statement printf("\n"); printf(" SPEECH STATISTICS : \n"); printf(" average power: %f \n",);//complete the statement printf(" average magnitude: %f...
C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...
Explain what the problem is within the program. Fix the problem when you create a child process per column. The code is given below. So basically, after the child processes have successfully excuted their code, the final print statement does not give the correct values. It prints the original matrix rather than the multiplied matrix.#include #include #include #include int main(int argc, char *argv[]){ int row = 0; int column = 0; row = atoi(argv[1]); column = atoi(argv[2]); int *A = ...
I'm having trouble sorting this square matrix (a 2d array that has number of rows and same number of column n x n) using row-wise approach in C programming. Please help me program this in C to sort it using row-wise approach, here is the code: #include <stdio.h> #define MAX 100 int main() { int mat[MAX][MAX]; int i, j, m, n; int rowsum, columnsum, diagonalsum; int k; int magic = 0; int transpose[MAX][MAX]; printf("Enter the # of rows and columns...
Help! i can't get the correct output for this question: Write a program that will read in an integer from the user and test to see whether or not it is prime. You are to determine if each integer read is prime or not, and output the result to the screen as shown below. If a number is prime, your output should read: 101 = 1 x 101 101: PRIME Number For a number that turns out not to be...