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; }
Can anyone help me to make this program work in C language, this is a blackjack game #include #include #include void deal(int, int&) void deal(int, int&, int&) int getbet(int); int main() { int totdealer, totplayer; int money, bet, aces; char yesno = 'Y'; _Bool again; srand(time(0)); printf("How much money do you have? "); scanf("%d" , money); while (money>0 && toupper(yesno) == 'Y') { bet = getbet(money); totdealer...
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 (...
Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...
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)...
Need help, i can't get a infinite loop to work, that terminates when a blank line is inputted for the firstName. note: C programing langauge and using microsoft visual studios . #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <math.h> #include <stdbool.h> int main() { //int arraySalaries[50]; int calculate_avg = 0; //int calculate_max; //int calculate_min; int salary[50]; //int length; //int average_salary; char firstName[50][50]; char lastName[50][50]; int i...
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])...