Programming (Sample Code Tutorial 6), Department of Biomedical Engineering, University of Malaya

You might also like

You are on page 1of 4

Muhammad Faiz Bin Zulkeflee, KEU100023

April 25, 2012


Question Code
1
#include<stdio.h>
#include<math.h>
#include<cstdlib>
void fx(void);
int main (void)
{
fx();
return 0;
}

void fx()
{
int a[99],x1,x2,x3,x4,x5,x6,x7;
x1=1; x2=3;
for (x1=1;x1<=x2;x1++)
{
printf("enter two integers: ");
scanf("%d %d",&a[0],&a[1]);
a[2]=a[0]%a[1];
a[3]=a[1]%a[0];
if (a[2] == 0)
{
printf("%d is a multiple of %d\n",a[0],a[1]);
}
else if (a[3] == 0)
{
printf("%d is a multiple of %d\n",a[1],a[0]);
}
else
{
if (a[0] >= a[1])
{
printf("%d is not a multiple of %d\n",a[0],a[1]);
}
else if (a[1] >= a[0])
{
printf("%d is not a multiple of %d\n",a[1],a[0]);
}
else
{}
}
printf("\n\n");
}
//return fx(g);
}

Muhammad Faiz Bin Zulkeflee, KEU100023


April 25, 2012
2

#include<stdio.h>
#include<math.h>
void fx(void);
int main (void)
{
fx();
return 0;
}
void fx()
{
int a[99], x1,x2,x3,x4,x5;
x2=3;
for (x1=1;x1<=x2;x1++)
{
printf("enter an integer: ");
scanf("%d",&a[x1]);
x3=a[x1]%2;
if (x3 == 0)
{
printf("%d is an even integer",a[x1]);
}
else if (x3 ==1)
{
printf("%d is an odd integer",a[x1]);
}
else
{}
printf("\n\n");
}
printf("\n");
//return 0;
}

Muhammad Faiz Bin Zulkeflee, KEU100023


April 25, 2012
3

#include<stdio.h>
#include<math.h>
void fx();
int main (void)
{
fx();
return 0;
}
void fx()
{
//int x,y;
//x=1; y=1;
double x1, y1, x0, y0, z[9];
printf("enter the first point: ");
scanf("%lf %lf",&x0 ,&y0);
printf("enter the second point: ");
scanf("%lf %lf",&x1 ,&y1);
z[0]=x0-x1; z[1]=pow(z[0],2);
z[2]=y0-y1; z[3]=pow(z[2],2);
z[4]=z[1]+z[3]; z[5]=pow(z[4],0.5);
printf("distance between <%.2lf,%.2lf> and <%.2lf,%.2lf> is
%.2lf\n",x0,y0,x1,y1,z[5]);
//return 0;
}

Muhammad Faiz Bin Zulkeflee, KEU100023


April 25, 2012
4

#include<stdio.h>
#include<math.h>
int main ()
{
int i[99], j[99], c, t;
t=100;
c=0;

for (int a=0; a<=t; a++)


{
printf("enter 5 integers between 10 and 100: ");
for (int b=0; b<=t; b++)
{
scanf("%d",&i[b]);
if (i[b]<=4)
{
b=100;
}
else if (i[b]>=100)
{
b=100;
}
else
{
j[c]=i[b];
if (c==4)
{
b=100;
a=100;
}
else
{
c++;
}
}
}
}
printf("\n5 integers between 10 and 100 are \n");
for (c=0;c<=4;c++)
{
printf("%d ",j[c]);
}
return 0;
}

You might also like