Professional Documents
Culture Documents
1. Write a function dotprod which has two float arrays a, b of fixed length N as
input parameters and returns the scalar product (PLEASE CHECK GERMEN
VERSION OF SHEET05)s = (summ)from i = 0 to N-1 * a [i] b [i]. In this context, N
is defined as a macro in the framework program.
#include<stdio.h>
#include<conio.h>
#define N 10
void main()
float a[N],b[N];
float k;
int i,j;
clrscr();
for(i=0;i<N;i++)
a[i]=0;
b[i]=0;
for(i=0;i<N;i++)
scanf("%f",&a[i]);
for(i=0;i<N;i++)
{
scanf("%f",&b[i]);
k=dotprod(a,b);
getch();
float scalar=0.00;
int j;
for(j=0;j<N;j++)
scalar=scalar+(a1[j]*b1[j]);
return scalar;
}
2. Write a function maxelement that has a fixed-length float array N as an input
parameter and returns the largest-value element
#include<stdio.h>
#include<conio.h>
void main()
float k,a[100];
int s,i;
clrscr();
scanf("%d",&s);
printf("Enter %d integers\n",s);
for(i=0;i<s;i++)
scanf("%f", &a[i]);
k=maxelement(a,s);
getch();
float max=ar[0];
int i;
for(i=0;i<size;i++ )
if(ar[i]<ar[i+1])
max=ar[i+1];
}
}
return max;
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
float main()
float *ans,*first,*second;
float *A,*B,*C;
float i,j,k=0;
float rowA,colA,sizeA,sizeB,sizeC;
float rowB,colB;
scanf("%d%d",&rowA,&colA);
scanf("%d%d",&rowB,&colB);
if(colA!=rowB)
getch();
exit(EXIT_SUCCESS);
}
k=dotprod(a,b);
getch();
sizeC = rowA*colB;
sizeA = rowA*colA;
sizeB = rowB*colB;
first = A;
second = B;
for(i=0;i<rowA;i++)
for(j=0;j<colB;j++)
*ans=0;
for(k=0;k<rowB;k++)
ans++;
}//j
}//i
}//if
else
for(i=0;i<rowA;i++)
for(j=0;j<colB;j++)
*ans=0;
for(k=0;k<rowB;k++)
ans++;
}//j
}//i
ans = C;
for(i=0;i<rowA;i++)
prfloatf("\n");
for(j=0;j<colB;j++,ans++)
prfloatf("%d\t",*ans);
free(A);
free(B);
free(C);
getch();
4. Write a swap function that gets two pointers to int variables a, b, and swaps
the contents of a and b.
#include<stdio.h>
#include<conio.h>
void main()
int a,b;
scanf("%d%d",&a,&b);
swap(&a, &b);
getch();
int temp;
temp = *a;
*a = *b;
*b = temp;
}
5. Write a program in which an int32_t variable x is declared and the contents of
the following four bytes are output as an int variable with printf.
#include<stdio.h>
#include<conio.h>
void main()
long x;
int i;
scanf("%ld",&x);
for (i=0;i<sizeof(x);i++)
getch();
}
6. Write a program for the multiplication of two matrices A ? R^(k, m) and B?
R^(m, n), where k, m, n?N are fixed. Test your program using the example
(PLEASE CHECK GERMEN VERSION OF SHEET05)A =( 1 2 3
4 5 6 ),
B = ( -1 0 1 4
0 1 -1 -3
2 1 3 0 ).
#include <stdio.h>
#include<conio.h>
void main()
{
int m, n, p, q, c, d, k, sum = 0;
scanf("%d", &first[c][d]);
if (n != p)
else
scanf("%d", &second[c][d]);
multiply[c][d] = sum;
sum = 0;
printf("%d\t", multiply[c][d]);
printf("\n");
getch();
}
7. Write a program in which an int array arr of length 5 is de fi ned. The fields of
arr are to be filled and output with their addresses converted to int. What can
you see at the output?
#include<stdio.h>
#include<conio.h>
void main()
int a[5];
int i;
clrscr();
for(i=0;i<5;i++)
scanf("%d",a[i]);
for(i=0;i<5;i++)
printf("%d",int(&a[i]));
getch();
#include<stdio.h>
#include<conio.h>
void main()
int a[100];
int s,i;
int k;
clrscr();
printf("Enter the number of elements in array\n");
scanf("%d",&s);
printf("Enter %d integers\n",s);
for(i=0;i<s;i++)
scanf("%d", &a[i]);
k=findmin(a,s);
getch();
int min=ar[0];
int i;
for(i=0;i<size;i++ )
if(ar[i]>ar[i+1])
min=(int)&ar[i+1];
return min;
}
9. Write a functioncycle3 that has , the pointer to the3 variables a, b, c,as
parameter and cyclically interchanges the contents of these variables. Example:
a = 6, b = 4, c = 5 should have the values a = 5, b = 6, c = 4 according to the
function.
#include<stdio.h>
#include<conio.h>
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
getch();
int temp;
temp = *b;
*b = *a;
*a = *c;
*c = temp;