22.3.11

tutorial 14

tutorial 14(1)

#include< stdio.h>
int main()
{
int n=1,i,j,a[10][10];


for(i=0;i<11;i++)
printf("%4d|",i);


printf("\n---------------------------------------------------\n");


for(i=0;i<10;i++)
{
printf("%4d|",n);
n++;


for(j=0;j<10;j++)
{
a[i][j]=(i+1)*(j+1);
printf("%4d|", a[i][j]);
}
printf("\n");
}
return 0;
}

tutorial 14(2)


#include< stdio.h>
int main()



{
int i,j,x[2][3],y[3][2],z[2][2];

printf("enter value of matrix X 2x3 seperated by a space: ");
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
scanf("%d", &x[i][j]);
}


printf("enter value of matrix Y 3x2 seperated by a space: ");
for(i=0; i<3; i++)
{
for(j=0; j<2; j++)
scanf("%d", &y[i][j]);
}

printf("\nMatrix X\n_________\n");
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
printf("%2d", x[i][j]);
printf("\n");
}

printf("\nMatrix Y\n_________\n");
for(i=0; i<3; i++)
{
for(j=0;j<2;j++)
printf("%2d", y[i][j]);
printf("\n");
}

printf("\nMatrix Z 2x2\n---------\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
z[i][j]=x[i][0]*y[0][j]+x[i][1]*y[1][j]+x[i][2]*y[2][j];
printf("%3d",z[i][j]);
}
printf("\n");
}
return 0;
}



tutorial 14(3)
#include< stdio.h>
#include< math.h>

double sum(int r);

int main()
{
    int r;

    printf("Enter the value of r > 0 : ");
    scanf("%d",&r);

    printf("The answer is %.2f\n\n",sum(r));
    return 0;
}

double sum(int n)
{
    if(n==0)
        return 2;
    else
        return (pow(2,2*n+1)/(2*n+1)+sum(n-1));
}



tutorial 14(4)



#include< stdio.h>
#include< math.h>

int main()
{
    double score[8], totalscore=0.0,lowest,max,average;
    int i;

    printf("enter 8 scores out of ten points separated by a space:\n");

    for(i=0;i<8;i++);
    {
        scanf("%lf",&score[i]);
        totalscore=totalscore+score[i];
    }
    average=totalscore/8.0;

    lowest=score[0];
    max=score[0];
    for(i=0;i<8;i++)
    {
        if(lowest>score[i])
        {
            lowest=score[i];
        }
        if(max
        {
            max=score[i];
        }
    }

    printf("\nThe lowest score is %.2lf\n",lowest);
    printf("The max score is %.2lf\n",max);
    printf("The total score is %.2lf\n",totalscore);
    printf("The average score is %.2lf\n",average);

    return 0;
}





mungkin ada yg salah...pandai2 la betul kan..hahaha
5 najashark.net: tutorial 14 tutorial 14(1) #include< stdio.h> int main() { int n=1,i,j,a[10][10]; for(i=0;i<11;i++) printf("%4d|",i); ...

No comments:

Post a Comment

Post Comment

< >