C programmning help
Vector permutation
can anyone explain whats happening in the bold statements ? im not too sure about it . thank you
//z5285994
#include <stdio.h>
#include <math.h>
int main(void){
int vector_length, v1[1000], permutation[1000];
printf("Enter vector length: ");
scanf("%d", &vector_length);
int i;
printf("Enter vector: ");
for (i=1;i<= vector_length; i++){
scanf("%d",&v1[i]);
}
printf("Enter permutation: ");
for (i = 1; i <= vector_length; i++){
scanf("%d", &permutation[i]);
}
for (i = 1;i <= vector_length; i++){
printf("%d ", v1[permutation[i]+1]);
}
printf("\n");
return 0;
}
#include <stdio.h>//includes standard
libraries.
#include <math.h>//includes math
libraries.
int main(void) //main function which has void as argument..
ie it takes nothing or void as argument.
{
int vector_length, v1[1000], permutation[1000]; //
vector_length is a variable of integer type and v1[1000] and
permutation[1000] are array of size 1000 of integer
type.
printf("Enter vector length: ");
scanf("%d", &vector_length); //this statement stores
the length of the vector.. example:vector length is 2.
int i;// i is a variable of integer type.
printf("Enter vector: ");
for (i=1;i<= vector_length; i++) //number of iteration of this for loop is less than or equal to the lenght of vector.. by the example: iteration is 2 times.
{
scanf("%d",&v1[i]); //inside the for loop
numbers of elements are stored into the array v1. That is:v1[1]
stores a given number in 1st iteration then v1[2] stores another
number in the second iteration and so on depending on the number of
iteration(in this case vector lenght).
}
printf("Enter permutation: ");
for (i = 1; i <= vector_length; i++) //this for loop is same as above for loop and repeats itself if 'i' is less than or equal to the vector length. ie: iterates 2 times
{
scanf("%d", &permutation[i]);// it stores number of
elements in the permutation array. ie: permutation[1] stores a
given number in its 1st iteration and permutation[2] stores another
number in other iteration.
}
for (i = 1;i <= vector_length; i++) //this for loop
prints the value for number of iterations which is less than or
equal to the vector length.
{
printf("%d ", v1[permutation[i]+1]);
// prints the array v1[permutation[i]+1]
=>v1[permutation[1]+1] =>v1[permutation[2]] => v1[given
number] if there is any number stored at the index of
v1[permutation[i]+1] then it may print the value or else 0 or
garbage value(by the example if vector length is 2).
//this process repeats for no of iterations which is less
than or equal to vector length.
}
printf("\n");//\n is an escape sequence used to print on
next line
return 0;
}
//hope it helps
C programmning help Vector permutation can anyone explain whats happening in the bold statements ? im...
I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }
3) (10 pts) For the purposes of this question, a permutation of size n is any ordering of the integers 0, 1, 2, ..., n-1. We define a spaced-out permutation of size n to be a permutation such that two consecutive terms in the permutation differ by at least 2. For example, [0, 2, 4, 1, 3] is a spaced out permutation of size 5, and [5, 2, 4, 0, 3, 1] is a spaced out permutation of size 6,...
Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...
C programming - This is what I have so far but it is not working correctly. It must contain the function and it also needs a provision to write output to a file. Can anyone help? #include <stdio.h> I #include <math.h int main (void) int V float Rint, RLE0, 0; printf New power supply voltage scanf ("td", &V) printf Enter a valid Internal Resistance (Rint) range between 200 and 5k ohms: scanf ("tf", Rint if (V> 1 && VK 15)...
Whats wrong with my code? Please help! #include <stdio.h> int main() { //variables int m1, m2, m3; int a1, a2, a3; int f1, f2, f3; //input acceleration printf("Enter value for a1: "); printf("Enter value for a2: "); printf("Enter value for a3: "); scanf("%d %d %d",&a1,&a2,&a3); //input mass printf("Enter value for m1: "); printf("Enter value for m2: "); printf("Enter value for m3: "); scanf("%d %d %d",&m1,&m2,&m3); //functions f1=m1*a1; m1=f1/a1; a1=f1/m1; f2=m2*a2; m2=f2/a2; a2=f2/m2; f3=m3*a3; m3=f3/a3; a3=f3/m3; //command: printf("f1=%d\n, m1=%d\n, a1=%d\n"); printf("f2=%d\n,...
C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () { int numDucks,numCats; getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...
NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A FUNCTION. Problem are explained in bold #include <stdio.h> #include <string.h> #include <stdlib.h> #define pi 3.1415 void Area (double n); void VolSphere (double n); void Circumference (double n); void AllCalc (); // i dont know if the declaration of the function is correct AllCalc = AllCalculations //function main begins program execution int main (void) { puts("-Calculating Circle Circumference, Circle Area or Sphere Volume-\n"); void (*f[4])...
I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong? #include<stdio.h> int main(void) { char first, last; int pennies; int nickels; int dimes; int quarters; int loonies; int change; int t_dollars; int t_cents; printf("Type in your 2 initials and press return> "); scanf("%c%c",&first,&last); printf("%c%c please enter in your...
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...