Want this question answered?
I don't program in just C (I use C++) so you may have to change some of the code:int main(){int n;int last = 1;int slast = 0;int numbers[n];numbers[0] = 1;for(int i = 1; i < n; i++){numbers[i] = last + slast;slast = last;last = numbers[i];}return 0;}int n needs to be set to however many Fibonacci numbers you want to make.int last is the last number in the sequence (so far)int slast is the second last number in the sequence (so far)int numbers[n] is the int array which holds your numbersint i is the count for the loop, it is set to 1 because before the loop, I set numbers[0] to 1
int linearSearch(int a[], int first, int last, int key) { // function: // Searches a[first]..a[last] for key. // returns: index of the matching element if it finds key, // otherwise -1. // parameters: // a in array of (possibly unsorted) values. // first, last in lower and upper subscript bounds // key in value to search for. // returns: // index of key, or -1 if key is not in the array. for (int i=first; i<=last; i++) { if (key == a[i]) { return i; } } return -1; // failed to find key }
//This is for kth largest element. (So this is for n-k smallest element) //Sudipta Kundu [Wipro Technologies] #include <stdio.h> //Input: array with index range [first, last) //Output: new index of the pivot. An element in the middle is chosen to be a pivot. Then the array's elements are //placed in such way that all elements <= pivot are to the left and all elements >= pivot are to the right. int positionPivot(int* array, int first, int last); //Input: array with index range [first, last) and integer K (first <= K < last) //Output: array whose Kth element (i.e. array[K]) has the "correct" position. More precisely, //array[first ... K - 1] <= array[K] <= array[K + 1 ... last - 1] void positionKthElement(int* array, int first, int last, int k); int main() { int array[] = {7,1,8,3,1,9,4,8}; int i; for (i = 0; i < 8; i++) { positionKthElement(array, 0, sizeof(array) / sizeof(array[0]),i); printf("%d is at position %d\n", array[i], i); } return 0; } int positionPivot(int* array, int first, int last) { if (first last) return first; int tmp = (first + last) / 2; int pivot = array[tmp]; int movingUp = first + 1; int movingDown = last - 1; array[tmp] = array[first]; array[first] = pivot; while (movingUp <= movingDown) { while (movingUp <= movingDown && array[movingUp] < pivot) ++movingUp; while (pivot < array[movingDown]) --movingDown; if (movingUp <= movingDown) { tmp = array[movingUp]; array[movingUp] = array[movingDown]; array[movingDown] = tmp; ++movingUp; --movingDown; } } array[first] = array[movingDown]; array[movingDown] = pivot; return movingDown; } void positionKthElement(int* array, int first, int last, int k) { int index; while ((index = positionPivot(array, first, last)) != k) { if (k < index) last = index; else first = index + 1; } }
#include#includevoid main(){int a,b;clrscr();printf("Enter 2 numbers:");scanf("%d %d",&a,&b);if(a>b)printf("%d is greater than %d",a,b);elseprintf("%d is greater than %d",b,a);getch();}
int lastLargestIndex(int a[],int n) //a=array, n= number of elements in array { int max=a[0],maxp=0; //max=largest no., maxp= position of largest no. for(int i=0;i<n;i++) if(a[i]>=max) { max=a[i]; maxp=i; } return maxp; }
I don't program in just C (I use C++) so you may have to change some of the code:int main(){int n;int last = 1;int slast = 0;int numbers[n];numbers[0] = 1;for(int i = 1; i < n; i++){numbers[i] = last + slast;slast = last;last = numbers[i];}return 0;}int n needs to be set to however many Fibonacci numbers you want to make.int last is the last number in the sequence (so far)int slast is the second last number in the sequence (so far)int numbers[n] is the int array which holds your numbersint i is the count for the loop, it is set to 1 because before the loop, I set numbers[0] to 1
describe the 5 steps to convert fuel into electrical energy
int linearSearch(int a[], int first, int last, int key) { // function: // Searches a[first]..a[last] for key. // returns: index of the matching element if it finds key, // otherwise -1. // parameters: // a in array of (possibly unsorted) values. // first, last in lower and upper subscript bounds // key in value to search for. // returns: // index of key, or -1 if key is not in the array. for (int i=first; i<=last; i++) { if (key == a[i]) { return i; } } return -1; // failed to find key }
//This is for kth largest element. (So this is for n-k smallest element) //Sudipta Kundu [Wipro Technologies] #include <stdio.h> //Input: array with index range [first, last) //Output: new index of the pivot. An element in the middle is chosen to be a pivot. Then the array's elements are //placed in such way that all elements <= pivot are to the left and all elements >= pivot are to the right. int positionPivot(int* array, int first, int last); //Input: array with index range [first, last) and integer K (first <= K < last) //Output: array whose Kth element (i.e. array[K]) has the "correct" position. More precisely, //array[first ... K - 1] <= array[K] <= array[K + 1 ... last - 1] void positionKthElement(int* array, int first, int last, int k); int main() { int array[] = {7,1,8,3,1,9,4,8}; int i; for (i = 0; i < 8; i++) { positionKthElement(array, 0, sizeof(array) / sizeof(array[0]),i); printf("%d is at position %d\n", array[i], i); } return 0; } int positionPivot(int* array, int first, int last) { if (first last) return first; int tmp = (first + last) / 2; int pivot = array[tmp]; int movingUp = first + 1; int movingDown = last - 1; array[tmp] = array[first]; array[first] = pivot; while (movingUp <= movingDown) { while (movingUp <= movingDown && array[movingUp] < pivot) ++movingUp; while (pivot < array[movingDown]) --movingDown; if (movingUp <= movingDown) { tmp = array[movingUp]; array[movingUp] = array[movingDown]; array[movingDown] = tmp; ++movingUp; --movingDown; } } array[first] = array[movingDown]; array[movingDown] = pivot; return movingDown; } void positionKthElement(int* array, int first, int last, int k) { int index; while ((index = positionPivot(array, first, last)) != k) { if (k < index) last = index; else first = index + 1; } }
Younis Khan.
C Programming Coding For DDA Algorithmvoid linedda(int xa,int ya,int xb,int yb) {int dx=xb-xa,dy=yb-ya,steps,k;float xincrement,yincrement,x=xa,y=ya;if(abs(dx)>abs(dy)) steps=abs(dx);else steps=abs(dy);xincrement=dx/(float)steps;yincrement=dy/(float)steps;putpixel(round(x),round(y),2)for(k=0;k
Your question is not clear but i can write a program to find the sum of n natural numbers. #include<iostream.h> #include<conio.h> int main() { long int res=0; int last; cout<<"enter the last number."; cin>>last; for(int i=0;i<=last;i++) res=res+i; cout<<"Result is "<<res<<endl; return 0; }
The last place he played was in Yankee stadium
#include#includevoid main(){int a,b;clrscr();printf("Enter 2 numbers:");scanf("%d %d",&a,&b);if(a>b)printf("%d is greater than %d",a,b);elseprintf("%d is greater than %d",b,a);getch();}
int n1; int n2; int n3; int n4; int n5; int n6; int n7; int n8; int n9; int n10; int n11; int n12; int n13; int n14; int n15; int n16; int n17; int n18; int n19; int n20; int n21; int n22; int n23; int n24; int n25; int n26; int n27; int n28; int n29; int n30;
five steps of the air force risk management process
int lastLargestIndex(int a[],int n) //a=array, n= number of elements in array { int max=a[0],maxp=0; //max=largest no., maxp= position of largest no. for(int i=0;i<n;i++) if(a[i]>=max) { max=a[i]; maxp=i; } return maxp; }