swap (int *a, int *b) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
int c = 13;
int d = 27;
swap (&c, &d); /*c is now 27 and d is now 13 */
Note: there is no call-by-reference in C. In C++:
void swap (int &a, int &b)
{
. int tmp;
. tmp = a;
. a = b;
. b = tmp;
}
2 answers
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;
1 answer
// declare a function
int* function(int, int);
or
int* (function)(int, int);
// declare a pointer to a function
int* (*pointer_to_function)(int, int);
1 answer
Any of its factors and the product of its prime factors are 2*3*13 = 78
1 answer
/* This programe will produce output as given series */
# include
# include
main()
{
int i,t,old=0,current=1,new;
clrscr();
printf(" %d \t", current);
fibo (old,current);
getch();
}
fibo(int old,int current)
{
static int count=2;
int new;
if (count
1 answer
#include <iostream>02using namespace std;
03
04int main()
05{
06 int sum = 0;
07 int average = 0;
08 int array[10] = {1,2,3,4,5,6,7,8,9,10};
09 for (int i = 0; i < 10; ++i)
10 sum+=array[i];
11 average = sum/10;
12 cout<<"Average:"<<average;
13}
1 answer
int LCM3 (int a, int b, int c)
{
return LCM2 (a, LCM2 (b, c));
}
int LCM2 (int a, int b)
{
return a*b/GCD2(a, b);
}
1 answer
int sum(int list[], int arraySize) {
int sum=0;
for(int i=0; i<arraySize; ++i )
sum+=list[i];
return(sum);
}
1 answer
I will explain in the easiest way the difference between the function and recursive function in C language.
Simple Answer is argument of the function is differ but in the recursive function it is same:)
Explanation:
Function
int function(int,int)// function declaration
main()
{
int n;
......
......
n=function(a,b);
}
int function(int c,int d)
{
......
......
......
}
recursive Function:
int recursive(int,int)// recursive Function declaration
main()
{
int n;
.....
.....
.....
.....
n=recursive(a,b);
}
int recursive(int a,int b)
{
.....
....
....
....
}
Carefully see, In the recursive Function the function arguments are same.
1 answer
Are you sure that these words (normal int and regular int) actually mean something?
1 answer
int a; -- variable definition
"int a" -- string literal
1 answer
By type casting since int is of larger bits than short
s=(int)i;
1 answer
int min(int list[], int arraySize) {
int min=arraySize?list[0]:0;
for(int i=1; i<arraySize; ++i )
if(list[i]<min)
m=list[i];
return(min);
}
1 answer
pick one:
int main (void);
int main (int argc, char **argv);
int main (int argc, char **argv, char **envp);
1 answer
int smallest_positive(int a, int b, int c) {
int s = 0;
while (a && b && c) {
s++;
a--; b--; c--;
}
return s;
// works only for positive integers
}
int smallest(int a, int b, int c) {
int test = INT_MIN;
while ((a-test) && (b-test) && (c-test))
test++;
return test;
}
1 answer
No such thing, pick one ot the three:
static int x;
extern int x;
int x;
1 answer
int max (int a, int b) {
return a<b?b:a;
}
int max3 (int a, int b, int c) {
return max (max (a, b), c);
}
1 answer
#include
#include
int *bubble(int a[],int n);
int *y;
int j,i;
void main()
{
int value[]={10,2,3,5,9,6,2,3,6,8};
int n;
clrscr();
n=sizeof(value)/sizeof(int);
y=bubble(value,n);
for(i=0;i
printf("%d\n",*y++);
}
getch();
}
int *bubble(int a[],int n)
{
int t;
for(i=0;i
for(j=0;j
if(a[j]<=a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
return a;
}
1 answer
public int sum(int[] x) {
int sum = 0;
for(int i : x) {
sum += i;
}
return sum;
}
public int average(int[] x) {
// Note that this returns an int, truncating any decimal
return sum(x) / x.length;
}
1 answer
void swap(int array1[],int array2[],int numberOfElements)
{
for(int i=0;i<numberOfElements;i++){
int temp=array1[i];array1[i]=array2[i];array2[i]=temp;}
}
1 answer
printf ("sizeof (int) is %d bytes", (int)sizeof (int));
Most likely it will be 2 or 4.
1 answer
Find the largest of two, then find the largest of that value and the third value.
int* max (int* a, int* b) {
return (a*) > (b*) ? a : b;
}
int* max_of_three (int* a, int* b, int* c) {
return max (max (a, b), c);
}
1 answer
At Level 80:
INT: 200
WIS: 50
END: 75
LUK: 50
CHA: 20
At Level 70:
INT: 200
WIS: 50
END: 75
CHA: 20
At Level 60:
INT: 200
WIS: 45
END: 50
At Level 50:
INT: 200
WIS: 25
END: 20
At Level 40:
INT: 150
WIS: 25
END: 20
At Level 30:
INT: 100
WIS: 25
END: 20
At Level 20:
INT: 50
WIS: 25
END: 20
At Level 10:
INT: 20
WIS: 25
Arcane Destroyer
At Level 80:
INT: 200
LUK: 150
WIS: 45
At Level 70:
INT: 200
LUK: 100
WIS: 45
At Level 60:
INT: 200
LUK: 50
WIS: 45
At Level 50:
INT: 200
WIS: 45
At Level 40:
INT: 170
WIS: 25
At Level 30:
INT: 120
WIS: 25
At Level 20:
INT: 70
WIS 25
At Level 10:
INT: 20
WIS: 25
Tank
At Level 80:
INT: 150
END: 200
WIS: 45
At Level 70:
INT: 150
END: 150
WIS: 45
At Level 60:
INT: 150
END: 100
WIS: 45
At Level 50:
INT: 100
END: 100
WIS: 45
At Level 40:
INT: 75
END: 75
WIS: 45
At Level 30:
INT: 75
END: 45
WIS: 25
At Level 20:
INT: 40
END: 30
WIS: 25
At Level 10:
INT: 10
END: 10
WIS: 25
1 answer
An example might help you:
extern int function1 (int parameter);
extern int function2 (int parameter);
int (*function_pointer_variable)(int parameter);
function_pointer_variable = function1;
(*function_pointer_variable)(12); /* call function1 */
function_pointer_variable = function2;
(*function_pointer_variable)(33); /* call function2 */
1 answer
typedef float (*pt_func)(int, int); pt_func arr[3];
another way:
float (*pt_func[3])(int, int);
2 answers
void math(int*, int*, int*, int*)
void main()
{
int a, b, c, d;
puts("ENTER VALUES TO A & B");
math(&a,&b,&c,&d);
printf("sum= %d \n diff= %d", c,d);
getch();
}
void math( int*a, int*b, int*c, int*d)
{
*c= *a+*b;
*d= *a-*b;
}
1 answer
The following code displays a 2D array with 4 rows and 3 columns. #include using namespace std; void print(int A[][3],int N, int M){ for (R = 0; R < N; R++) for (C = 0; C < M; C++) cout << A[R][C];}int main (){ int arr[4][3] ={{12, 29, 11}, {25, 25, 13}, {24, 64, 67}, {11, 18, 14}}; print(arr,4,3); return 0;}
1 answer
Through Week 9 of the 2010 season ...
13 defensive TDs - Darren Sharper (11 INT returns and 2 fumble returns) and Rod Woodson (12 INT returns and 1 fumble return).
12 defensive TDs - Aeneas Williams (9 INT returns and 3 fumble returns).
11 defensive TDs - Ronde Barber (7 INT returns and 4 fumble returns) and Charles Woodson (10 INT returns and 1 fumble return).
1 answer
int* a = new int(40);
int* b = new int(2);
int x = *a + *b; // x = 42
delete b;
delete a;
1 answer
In Java:
int[] myArray;
// or: int myArray[]
followed by:
myArray = new int[16];
Instead of int, you can use any other data type, including a class.
3 answers
#include<stdio.h>
#include<malloc.h>
int* getpoly(int);
void showpoly(int *,int);
int* addpoly(int *,int,int *,int);
int* mulpoly(int *,int,int *,int);
int main(void)
{
int *p1,*p2,*p3,d1,d2,d3;
/*get poly*/
printf("\nEnter the degree of the 1st polynomial:");
scanf("%d",&d1);
p1=getpoly(d1);
printf("\nEnter the degree of the 2nd polynomial:");
scanf("%d",&d2);
p2=getpoly(d2);
printf("Polynomials entered are\n\n");
showpoly(p1,d1);
printf("and\n\n");
showpoly(p2,d2);
/*compute the sum*/
d3=(d1>=d2?d1:d2);
p3=addpoly(p1,d1,p2,d2);
printf("Sum of the polynomials is:\n");
showpoly(p3,d3);
/*compute product*/
p3=mulpoly(p1,d1,p2,d2);
printf("Product of the polynomials is:\n");
showpoly(p3,d1+d2);
}
int* getpoly(int degree)
{
int i,*p;
p=malloc((1+degree)*sizeof(int));
for(i=0;i<=degree;i++)
{
printf("\nEnter coefficient of x^%d:",i);
scanf("%d",(p+i));
}
return(p);
}
void showpoly(int *p,int degree)
{
int i;
for(i=0;i<=degree;i++)
printf("%dx^%d + ",*(p+i),i);
printf("\b\b\b ");
printf("\n");
}
int* addpoly(int *p1,int d1,int *p2,int d2)
{
int i,degree,*p;
degree=(d1>=d2?d1:d2);
p=malloc((1+degree)*sizeof(int));
for (i=0;i<=degree;i++)
if((i>d1) && (i<=d2))
*(p+i)=*(p2+i);
else if((i>d2) && (i<=d1))
*(p+i)=*(p1+i);
else
*(p+i)=*(p1+i)+*(p2+i);
return(p);
}
int* mulpoly(int *p1,int d1,int*p2,int d2)/* this is the function of concern*/
{
int i,j,*p;
p=malloc((1+d1+d2)*sizeof(int));
for(i=0;i<=d1;i++)
for(j=0;j<=d2;j++)
p[i+j]+=p1[i]*p2[j];
return(p);
}
1 answer
int max(int arr[], int arrSize)
{
int maximum = arr[0];
for (int i = 0; i < arrSize; i++)
{
if (maximum < arr[i])
{
maximum = arr;
}
}
return maximum;
}
1 answer
#include<stdio.h>
#define MAXVAL 1000
void sort1(int a[],int n);
void median(int a[],int n);
void mode(int a[],int n);
int main()
{
int n;
int arr[MAXVAL];
int i;
printf("Enter the number of elements:");
scanf("%d",&n);
printf("Enter the values:");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",&arr[i]);
}
sort1(arr,n);
median(arr,n);
mode(arr,n);
}
void sort1(int a[],int n)
{
int i;
int j;
int temp;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void median(int a[],int n)
{
int median;
int mid;
if((n%2)==0)
{
mid=n/2;
median=(a[mid-1]+a[mid])/2;
}
else
{
mid=(n+1)/2;
median=a[mid-1];
}
printf("The median is:%d\n",median);
}
void mode(int a[],int n)
{
int i;
int count1[MAXVAL];
for(i=0;i<n;i++)
{
count1[i]=0;
}
for(i=0;i<n;i++)
{
count1[a[i]]++;
}
i--;
int mode=count1[0];
int j;
int k;
int flag=0;
for(j=0;j<=a[i];j++)
{
if(count1[j]>count1[mode])
mode=j;
}
for(j=0;j<=a[i];j++)
{
for(k=j+1;k<=a[i];k++)
{
if(count1[j]=count1[k] && count1[j]>count1[mode])
{
flag=1;
}
}
}
if(flag==1)
{
printf("Mode cannot be calculated");
}
else
printf("the Mode is:%d",mode);
}
1 answer
minimalist: int main (void);
standard: int main (int argc, char **argv);
unix-only: int main (int argc, char **argv, char **envp);
1 answer
typedef float (*pt_func)(int, int); pt_func arr[3];
another way:
float (*pt_func[3])(int, int);
1 answer
int num1 = 1;
int num2 = 50;
int addition = num1 + num2;
2 answers
#include<iostream>
void insertion_sort(int* a,int len)
{
for(int i=1; i<len; ++i)
{
int* hole=a+i;
int* prev=hole-1;
int cur=*hole;
while(hole!=a && cur<*(prev))
{
*(hole)=*(prev);
--hole, --prev;
}
*hole=cur;
}
}
void print_array(int* a,int len)
{
for(int i=0; i<len; ++i)
std::cout<<a[i]<<" ";
std::cout<<std::endl;
}
int main()
{
int a[]={9,1,8,3,7,2,5,4,6};
int size=sizeof(a)/sizeof(a[0]);
std::cout<<"Before:\t";
print_array(a,size);
insertion_sort(a,size);
std::cout<<"After:\t";
print_array(a,size);
return(0);
}
1 answer
Direct:
int foo ()
{ ... foo (); ... }
Indirect:
int foo ()
{ ... bar (); ... }
int bar ()
{ ... foo (); ... }
1 answer
4 players
Ray Lewis- 30 Int 38.5 sacks
Ronde Barber- 39 Int 25 sacks
Rodney Harrison- 34 Int 30.5 sacks (Only player in NFL history with 30 career Int and 30 sacks)
William Thomas- 27 Int 37 Sacks (Eagles 91-99/ Raiders 00-01)
Other active players who are close
Brian Dawkins- 37 Int 22 sacks
Lawyer Milloy- 25 Int 21 sacks
Adrian Wilson- 25 Int 22.5 sacks
Brian Urlacher- 18 Int 40.5 sacks
Keith Bulluck- 19 Int 18 sacks
Closest Player who never made it
Wilbur Marshall- 23 Int 37 Sacks (Bears 84-87, Redskins 88-92, Oilers 93, Cardinals 94, Jets 95)
3 answers
#include <iostream.h> #include <conio.h> void main() { clrscr(); int largest(int,int,int); cout<<"Enter 3 Integer Numbers\n"; int a,b,c; cin>>a>>b>>c; int result; result=largest(a,b,c); cout<<"\n\nLargest Value of Inputed is "<<result; getch(); } inline largest(int a,int b,int c) { int z; z=(a>b)?((a>c)?a:c):((b>c)?b:c); return(z); }
1 answer
Answer: Between integers 6 and 7
Math:
5x = 3x + 13
5x -3x = 3x -3x + 13
2x = 13
(2x) : 2 = (13) : 2
Int (6) < (x = 6.5) < Int (7)
1 answer