Letusc PDF
Letusc PDF
#include<stdio.h>
void main()
{
int a[10],b[10],i,j;
clrscr();
printf("\nEnter Elements : ");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0,j=9;i<10;i++,j--)
{
b[i]=a[j];
}
printf("\nArray after Copying in Reverse Order : ");
for(i=0;i<10;i++)
{
printf("%d ",b[i]);
}
getch();
}
Output :
Enter Elements : 2 6 3 5 9 8 7 4 1 0
for(i=0;i<n;i++)
{
b[n-1-i]=a[i];
}
getch();
}
//***********************
//www.botskool.com
//***********************
int main()
{
int *ptr,i,n;
clrscr();
printf("Enter the no of elements:");
scanf("%d",&n);
ptr=(int *)malloc(sizeof(int)*n);
if(ptr==NULL)
{
printf("Not enough memory");
exit(1);
}
for(i=0; i<n; i++)
{
printf("Enter %d element : ",i+1);
scanf("%d",&ptr[i]);
}
printf("Array in original order\n");
for(i=0; i<n; i++)
{
printf("%d\n",ptr[i]);
}
printf("Array in reverse order\n");
for(i=n-1; i>=0; i--)
{
printf("%d\n",ptr[i]);
}
getch();
return 0;
}
void reverse( int array[], int length)
{
int ii, temp;
int jj = 0;
int *tempArray = (int)malloc( length * sizeof( int));
array = *tempArray;
temp = tempArray[ii];
array[ii] = temp;
free( tempArray);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[100],b[100];
printf("How many numbers you want to store:=\n");
scanf("%d",&j);
printf("Enter the numbers:=\n");
for(i=0;i<j;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<j;i++)
{
b[i]=a[j-i-1];
}
printf("Reversed order:=\n");
for(i=0;i<j;i++)
{
printf("%d\n",b[i]);
}
getch();
}
Write a program to copy the contents of one array into another in the reverse
order.
void main()
{
int arr1[5]={1,2,3,4,5};
int arr2[5];
int i,k;
for (i=4,k=0;i>=0;i--,k++)
arr2[k]=arr1[i];
for(i=0;i<5;i++)
printf("\nValue of arr2[%d] is %d",i,arr2[i]);
With Pointers
void main()
{
int arr1[5]={1,2,3,4,5};
int arr2[5];
int *m;
int i,*j,k,l=5;
j=arr1;
m=arr2;
func(j,m,l);
for(i=0;i<5;i++)
printf("\nValue of arr2[%d] is %d",i,arr2[i]);
}
#include<stdio.h>
#include<conio.h>
main()
{
int num[10];
int x;
for(x=0;x<10;x++)
{
printf("Enter number %d : ",x);
scanf("%d", &num[x]);
for(x=0;x<10;x++)
{
printf(" %d ",num[x]);
//clrscr ();
num[x]=0;
for(x=10;x>-1;x--)
{
printf(" %d ",num[x]);
getch();
}
C program to reverse an array: This program reverses the array elements. For example if a is
an array of integers with three elements such that
a[0] = 1
a[1] = 2
a[2] = 3
Then on reversing the array will be
a[0] = 3
a[1] = 2
a[0] = 1
C programming code
#include <stdio.h>
int main()
{
int n, c, d, a[100], b[100];
printf("Enter the number of elements in array\n");
scanf("%d", &n);
/*
* Copying elements into array b starting from end of array a
*/
/*
* Copying reversed array into original.
* Here we are modifying original array, this is optional.
*/
return 0;
}
Download Reverse array program.
Output of program:
Reverse array by swapping (without using additional memory)
#include <stdio.h>
int main() {
int array[100], n, c, t, end;
scanf("%d", &n);
end = n - 1;
end--;
}
return 0;
}
int main()
{
int n, c, *pointer;
scanf("%d",&n);
pointer = (int*)malloc(sizeof(int)*n);
reverse_array(pointer, n);
free(pointer);
return 0;
}
s = (int*)malloc(sizeof(int)*n);
if( s == NULL )
exit(EXIT_FAILURE);
free(s);
}
Chap 8[D]a Search quantity of instances in Array
Twenty-five numbers are entered from the keyboard into an array. The number to
be searched is entered through the keyboard by the user. Write a program to find
if the number to be searched is present in the array and if it is present, display the
number of times it appears in the array.
void main()
{
int arr[25];
int a,d,i;
for(i=0;i<25;i++)
{
printf("\nKey %d) value",i);
scanf("%d",&arr[i]);
}
for(i=0,a=0;i<25;i++)
{
if(arr[i]==d)
a++;
}
if(a>0)
printf("\nThe integer appeared %d times in the array",a);
else
printf("\nThe integer did not appear in the array");
}
hap8[D]b Finding +tive -tive zeros, odd and even numbers in array
Twenty-five numbers are entered from the keyboard into an array. Write a
program to find out how many of them are positive, how many are negative, how
many are even and how many odd.
void main()
{
int arr[25];
int a,b,c,d,e,i;
a=0;
b=0;
c=0;
d=0;
e=0;
for(i=0;i<25;i++)
{
printf("\nKey the %d) value",i);
scanf("%d",&arr[i]);
}
for(i=0;i<25;i++)
{
if(arr[i]>0)
a++;
if(arr[i]<0)
b++;
if(arr[i]==0)
c++;
if(arr[i]%2==0)
d++;
else
e++;
}
if(a>0)
printf("\nThere are %d positive integers",a);
if(b>0)
printf("\nThere are %d negative integers",b);
if(c>0)
printf("\nThere are %d zeros",c);
if(d>0)
printf("\nThere are %d even numbers",d);
if(e>0)
printf("\nThere are %d odd numbers",e);
}
Chap8[D]c Selection sort
Implement the Selection Sort, Bubble Sort and Insertion sort algorithms on a set
of 25 numbers. (Refer Figure 8.11 for the logic of the algorithms) − Selection sort
− Bubble Sort − Insertion Sort
/* Selection sort */
void main()
{
int arr[25];
int a,b,d,i;
for(i=0;i<24;i++)
{
for(d=i+1;d<25;d++)
{
a=arr[i];
b=arr[d];
arr[i]=b;
arr[d]=a;
}
}
for(i=0;i<25;i++)
Implement the Selection Sort, Bubble Sort and Insertion sort algorithms on a set
of 25 numbers. (Refer Figure 8.11 for the logic of the algorithms)− Selection sort
− Bubble Sort − Insertion Sort
/*Bubble sort*/
void main()
{
int arr[25];
int a,b,c,d,i;
for(i=0;i<25;i++)
{
printf("\nKey the %d) value",i);
scanf("%d",&arr[i]);
}
printf("\nStarting bubble sort");
for(i=24;i>0;i--)
{
for(b=0,c=b+1;c <=i;b++,c ++)
{
a=arr[b];
d=arr[c];
arr[b]=d;
arr[c]=a;
}
}
for(i=0;i<25;i++)
printf("\n%d value is %d",i,arr[i]);
}
Chap8[D]c Insertion sort
Implement the Selection Sort, Bubble Sort and Insertion sort algorithms on a set
of 25 numbers. (Refer Figure 8.11 for the logic of the algorithms) − Selection sort
− Bubble Sort − Insertion Sort
/*Insertion sort*/
void main()
{
int arr[25];
int a,b,c,i;
for(i=0;i<25;i++)
{
printf("\nKey in the %d) value",i);
scanf("%d",&arr[i]);
}
for(a=1;a<25;a++)
{
b=arr[0];
c=arr[a];
arr[0]=c;
arr[a]=b;
}
for(i=0;i<25;i++)
Implement the following procedure to generate prime numbers from 1 to 100 into
a program. This procedure is called sieve of Eratosthenes.
step 1 Fill an array num[100] with numbers from 1 to 100
step 2 Starting with the second entry in the array, set all its multiples to zero.
step 3 Proceed to the next non-zero element and set all its multiples to zero.
step 4 Repeat step 3 till you have set up the multiples of all the non-zero elements
to zero
step 5 At the conclusion of step 4, all the non-zero entries left in the array would
be prime numbers, so print out these numbers.
Chap8[I]a Reversing contents and copy to another array
Write a program to copy the contents of one array into another in the reverse
order.
void main()
{
int arr1[5]={1,2,3,4,5};
int arr2[5];
int i,k;
for (i=4,k=0;i>=0;i--,k++)
arr2[k]=arr1[i];
for(i=0;i<5;i++)
printf("\nValue of arr2[%d] is %d",i,arr2[i]);
With Pointers
void main()
{
int arr1[5]={1,2,3,4,5};
int arr2[5];
int *m;
int i,*j,k,l=5;
j=arr1;
m=arr2;
func(j,m,l);
for(i=0;i<5;i++)
printf("\nValue of arr2[%d] is %d",i,arr2[i]);
}
This program will have repeated results if the input contains more than 2 same integers
void main()
{
int arr[25];
int i,*j,k;
j=arr;
printf("\nInput 25 integers");
for(i=0;i<25;i++,j++)
{
printf("\nKey in the %d) value",i+1);
scanf("%d",&*j);
}
for(i=0;i<25;i++)
{
for(k=24;k>i;k--)
if(arr[i]==arr[k])
printf("\nArray [%d] = Array[%d]",i,k);
}
}
Chap8[I]c Finding smallest number in array using pointers
Find the smallest number in an array using pointers.
How will you initialize a three-dimensional array threed[3][2][3]? How will you
refer the first and last element in this array?
void main()
{
int threed[3][2][3]={
{
1,2,3,
4,5,6
},
{
7,8,9,
10,11,12
},
{
13,14,15,
16,17,18
}
};
Write a program to pick up the largest number from any 5 row by 5 column matrix.
void main()
{
int arr[4][4];
int i,j,a,b,f;
printf("\nInput numbers to 4*4 matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("\nKey in the [%d][%d]) value",i+1,j+1);
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0,f=0;j<4;j++)
{
if(i!=j&&f ==0)
continue;
a=arr[i][j];
b=arr[j][i];
arr[i][j]=b;
arr[j][i]=a;
f=1;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
}
void main()
{
char source[]="Folks!";
char target[30]="Hello";
scat(target,source);
printf("\nSource string = %s",source);
printf("\nTarget string = %s",target);
}
m++;
}
*m='\0';
}
Very often in fairs we come across a puzzle that contains 15 numbered square
pieces mounted on a frame. These pieces can be moved horizontally or vertically.
A possible arrangement of these pieces is shown below:
As you can see there is a blank at bottom right corner. Implement the following
procedure through a program:
Draw the boxes as shown above. Display the numbers in the above order. Allow
the user to hit any of the arrow keys (up, down, left, or right). If user hits say,
right arrow key then the piece with a number 5 should move to the right and blank
should replace the original position of 5. Similarly, if down arrow key is hit, then
13 should move down and blank should replace the original position of 13. If left
arrow key or up arrow key is hit then no action should be taken. The user would
continue hitting the arrow keys till the numbers aren’t arranged in ascending
order. Keep track of the number of moves in which the user mana ges to arrange
the numbers in ascending order. The user who manages it in minimum number of
moves is the one who wins. How do we tackle the arrow keys? We cannot receive
them using scanf( ) function. Arrow keys are special keys which are identified by
their ‘scan codes’. Use the following function in your program. It would return the
scan code of the arrow key being hit. Don’t worry about how this function is
written. We are going to deal with it later. The scan codes for the arrow keys are:
up arrow key – 72 down arrow key – 80 left arrow key – 75 right arrow key – 77
/* Returns scan code of the key that has been hit */
#include "dos.h"
getkey( )
{
union REGS i, o ;
while ( !kbhit( ) )
;
i.h.ah = 0 ;
int86 ( 22, &i, &o ) ;
return ( o.h.ah ) ;
}
ANS:
#include "dos.h"
void main()
{
void creategrid();
int g,c;
int arr[16]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0};
clrscr();
creategrid();
printarray(arr);
for(g=15,c=0;;)
{
int k,a,b,i;
k=getkey();
if(k==80)
{
if((g-4)<0) a="arr[g-4];" b="arr[g];" k="="72)">15)
continue;
a=arr[g+4];
b=arr[g];
arr[g+4]=b;
arr[g]=a;
go(g);
printf("%d",arr[g]);
go(g+4);
printf("%c%c",0,0);
go(g+4);
c++;
g+=4;
}
if(k==75)
{
if(g==3g==7g==11g==15)
continue;
a=arr[g+1];
b=arr[g];
arr[g+1]=b;
arr[g]=a;
go(g);
printf("%d",arr[g]);
go(g+1);
printf("%c%c",0,0);
go(g+1);
c++;
g+=1;
}
if(k==77)
{
if(g==0g==4g==8g==12)
continue;
a=arr[g-1];
b=arr[g];
arr[g-1]=b;
arr[g]=a;
go(g);
printf("%d",arr[g]);
go(g-1);
printf("%c%c",0,0);
go(g-1);
c++;
g-=1;
}
for(i=0;i<15;i++)
{
if(arr[i]!=i+1)
break;
if(arr[i]==(i+1)&&i==14)
{
gotoxy(6,24);
printf("\nNumber of moves to complete is %d",c);
exit();
}
}
}
go(int g)
{
switch(g)
{
case 0:
gotoxy(8,5);
break;
case 1:
gotoxy(12,5);
break;
case 2:
gotoxy(16,5);
break;
case 3:
gotoxy(20,5);
break;
case 4:
gotoxy(8,9);
break;
case 5:
gotoxy(12,9);
break;
case 6:
gotoxy(16,9);
break;
case 7:
gotoxy(20,9);
break;
case 8:
gotoxy(8,13);
break;
case 9:
gotoxy(12,13);
break;
case 10:
gotoxy(16,13);
break;
case 11:
gotoxy(20,13);
break;
case 12:
gotoxy(8,17);
break;
case 13:
gotoxy(12,17);
break;
case 14:
gotoxy(16,17);
break;
case 15:
gotoxy(20,17);
break;
}
}
getkey()
{
union REGS i,o;
while(!kbhit())
;
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
}
printarray(int *m)
{
int a,b,i,j;
for(a=5,i=0;a<=17;a+=4,i++)
{
for(b=8,j=0;b<=20;b+=4,j++)
{
gotoxy(b,a);
printf("%d",*(m+(i*4)+j));
}
}
gotoxy(20,17);
printf("%c",0);
void creategrid()
{
int a,b;
for(a=3;a<=19;a+=4)
{
for(b=6;b<=22;b++)
{
if(b==6(b-6)%4==0)
{
if(a==3)
{
if(b==6)
{
gotoxy(6,3);
printf("%c",218);
}
else if(b==22)
{
gotoxy(22,3);
printf("%c",191);
}
else
{
gotoxy(b,3);
printf("%c",194);
}
}
else if(a==19)
{
if(b==6)
{
gotoxy(6,19);
printf("%c",192);
}
else if(b==22)
{
gotoxy(22,19);
printf("%c",217);
}
else
{
gotoxy(b,19);
printf("%c",193);
}
}
else
{
if(b==6)
{
gotoxy(6,a);
printf("%c",195);
}
else if(b==22)
{
gotoxy(22,a);
printf("%c",180);
}
else
{
gotoxy(b,a);
printf("%c",197);
}
}
}
else
{
printf("%c",196);
}
}
}
for(b=6;b<=22;b+=4)
{
for(a=4;a<=18;a++)
{
if((a-3)%4==0)
continue;
else
{
gotoxy(b,a);
printf("%c",179);
}
}
}
}
Write a function to find the norm of a matrix. The norm is defined as the square
root of the sum of squares of all elements in the matrix.
for(i=0;i<6;i++)
{
for(j=0;j<3;j++)
{
printf("\nKey in the [%d][%d] value",i+1,j+1);
scanf("%f",&arr[i][j]);
}
}
for(i=0;i<6;i++)
area=(1.0/2.0)*arr[i][0]*arr[i][1]*sin(arr[i][2]);
if(area>c)
{ printf("\n1");
c=area;
d=i;
}
}
For the following set of n data points (x, y), compute the correlation coefficient r,
given by
void main()
{
float arr[11][2]={
34.22,102.43,
39.87,100.93,
41.85,97.43,
43.23,97.81,
40.06,98.32,
53.29,98.32,
53.29,100.07,
54.14,97.08,
49.12,91.59,
40.71,94.85,
55.15,94.65
};
int i,j;
float sx=0,sy=0,sx2=0,sy2=0,sxy=0,b,r;
for(i=0;i<11;i++)
sx=sx+arr[i][0];
printf("\nsummation x is %f",sx);
/*calculating summation y*/
for(i=0;i<11;i++)
sy=sy+arr[i][1];
printf("\nsummation y is %f",sy);
/*calculating summation x2*/
for(i=0;i<11;i++)
sx2=sx2+(arr[i][0]*arr[i][0]);
printf("\nsummation x2 is %f",sx2);
/*calculating summation y2*/
for(i=0;i<11;i++)
sy2=sy2+(arr[i][1]*arr[i][1]);
printf("\nsummation sy2 is %f",sy2);
/*calculating summation xy*/
for(i=0;i<11;i++)
sxy=sxy+(arr[i][0]*arr[i][1]);
printf("\nsummation sxy is %f",sxy);
r=(sxy-(sx*sy))/(sqrt(b));
printf("\n The correlation coefficient is %f",r);
}
For the following set of point given by (x, y) fit a straight line given by
y = a + bx
where,
void main()
{
float arr[10][2]={
3.0,1.5,
4.5,2.0,
5.5,3.5,
6.5,5.0,
7.5,6.0,
8.5,7.5,
8.0,9.0,
9.0,10.5,
9.5,12.0,
10.0,14.0
};
int i,j;
float sx=0,sy=0,sx2=0,sxy=0,my,mx,a,b;
/* for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
{
printf("\nKey in the [%d][%d] value",i+1,j+1);
scanf("%f",&arr[i][j]);
}
}
*/
/*calculating summation x*/
for(i=0;i<10;i++)
sx=sx+arr[i][0];
for(i=0;i<10;i++)
sx2=sx2+(arr[i][0]*arr[i][0]);
for(i=0;i<10;i++)
sxy=sxy+(arr[i][0]*arr[i][1]);
my=sy/i;
mx=sx/i;
b=((i*sxy)-(sx*sy))/((i*sx2)-(sx*sx));
a=my-(b*mx);
printf("\nThe value of a is %f\nThe value of b is %f",a,b);
}
void main()
{
char source[]="Folks!";
char target[30]="Hello";
scat(target,source);
printf("\nSource string = %s",source);
printf("\nTarget string = %s",target);
}
m++;
}
*m='\0';
}
et Us C / Chapter 8 (Arrays)
Exercise [D]
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,arr[25],prsnt=0,num;
clrscr();
for(i=0;i<25;i++) {
scanf("%d",&arr[i]);
scanf("%d",&num);
for(i=0;i<25;i++) {
if(num==arr[i])
prsnt=prsnt+1;
if(prsnt==0) {
else {
getch();
---------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,arr[25],tz=0,tp=0,tn=0;
clrscr();
for(i=0;i<25;i++) {
scanf("%d",&arr[i]);
if(arr[i]<0){
tn=tn+1;
if(arr[i]==0){
tz=tz+1;
if(arr[i]>0){
tp=tp+1;
----------------------------------------------------------------------------------------------------------------
Solution:
----------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,a[100];
clrscr();
for(i=0;i<100;i++) {
a[i]=i+1;
}
printf("\n100 numbers in the array:\n\n");
for(i=0;i<100;i++) {
printf("%3d ",a[i]);
for(i=2;i<100;i++) {
for(j=2;j<a[i];j++) {
if(a[i]%j==0)
a[i]=0;
i=a[0];
for(;i<100;i++) {
printf("%3d ",a[i]);
for(i=a[0];i<100;i++) {
if(a[i]!=0)
printf("%3d ",a[i]);
getch();
---------------------------------------------------------------------------------------------------------------
Exercise [I]
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,k,a1[5],a2[5];
clrscr();
for(i=1;i<=5;i++) {
scanf("%d",&a1[i]);
}
printf("\n\nThe elements you enterd are:\n");
for(i=1;i<=5;i++) {
printf(" %d",a1[i]);
for(i=5,j=1;i>=1,j<=5;i--,j++) {
k=a1[i];
a2[j]=k;
printf(" %d",a2[j]);
getch();
---------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int arr[100];
int n,i,f=0;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d",&arr[i]);
clrscr();
for(i=0;i<n;i++) {
it will be printed */
f=f+1;
if(f==0)
---------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,n,*p,*s,a[100];
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d",&a[i]);
}
clrscr();
for(i=0;i<n;i++) {
printf("%2d ",a[i]);
printf("\n\n");
for(i=0;i<n;i++) {
if(*p>*s)
getch();
}
----------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,a[10]={1,2,3,4,5,6,7,8,9,10};
modify();
clrscr();
for(i=0;i<10;i++) {
printf(" %d ",a[i]);
}
modify(a); /* passing only the name of array */
printf(" %d ",a[i]);
getch();
modify(int b[10]) {
int c;
for(c=0;c<10;c++) {
----------------------------------------------------------------------------------------------------------
Solution:
_______________________________________________________________________
Exercise [L]
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int threed[3][2][3]={
{100,2,3},
{1,2,3}
},
{8,5,6},
{4,5,6}
},
{7,8,9},
{7,8,200}
};
int *f,*l;
clrscr();
f=&threed[0][0][0]; /* reference to first element */
getch();
---------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,a[5][5];
clrscr();
for(j=0;j<5;j++) {
scanf("%d",&a[i][j]);
clrscr();
for(i=0;i<5;i++) {
for(j=0;j<5;j++) {
printf("\n");
for(i=0;i<5;i++) {
for(j=0;j<5;j++) {
getch();
---------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
#define MAX 4
void main() {
int i,j,a[4][4],b[4][4];
clrscr();
for(i=0;i<MAX;i++) {
for(j=0;j<MAX;j++) {
scanf("%d",&a[i][j]);
clrscr();
for(i=0;i<MAX;i++) {
for(j=0;j<MAX;j++) {
printf("%2d ",a[i][j]);
printf("\n");
/* transpose of matrix */
for(i=0;i<MAX;i++) {
for(j=0;j<MAX;j++) {
b[j][i]=a[i][j];
printf("\n\n");
for(i=0;i<MAX;i++) {
for(j=0;j<MAX;j++) {
printf("%2d ",b[i][j]);
printf("\n");
getch();
----------------------------------------------------------------------------------------------------------------
(d) Very often in fairs we come across a puzzle that
contains 15 numbered square pieces mounted on a
frame. These pieces can be moved horizontally or
vertically. A possible arrangement of these pieces is
shown below:
1 4 15 7
8 10 2 11
14 3 6 13
12 9 5
#include<stdio.h>
#include<conio.h>
#include<dos.h>
getkey()
while(!kbhit() )
i.h.ah=0;
int86(22,&i,&o);
return(o.h.ah);
void main() {
int i,j,a[16]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0};
int temp,h,moves=0,won=0;
clrscr();
/****************************************************/
do {
/**************/
/* to move up */
/**************/
if(h==72) {
for(i=0;i<16;i++) {
if(a[i]==0){
break;
temp=a[i];
a[i]=a[i-4];
a[i-4]=temp;
moves=moves+1;
break;
/****************/
/* to move left */
/****************/
if(h==75) {
for(i=0;i<16;i++) {
if(a[i]==0){
break;
temp=a[i];
a[i]=a[i-1];
a[i-1]=temp;
moves=moves+1;
break;
/****************/
/* to move down */
/****************/
if(h==80) {
for(i=0;i<16;i++) {
if(a[i]==0){
break;
temp=a[i];
a[i]=a[i+4];
a[i+4]=temp;
moves=moves+1;
break;
/*****************/
/* to move right */
/*****************/
if(h==77) {
for(i=0;i<16;i++) {
if(a[i]==0) {
break;
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
moves=moves+1;
break;
/***********************************************************/
/**********************************/
/**********************************/
printf("\n%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n",218,196,196,196,194,196,196,196,194,
196,196,196,194,196,196,196,191);
for(i=0;i<=15;i++) {
printf("%c",179);
if(a[i]==0) {
}
if(a[i]!=0)
printf(" %2d",a[i]);
printf("%c",179);
if(i==3||i==7||i==11)
printf("\n%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n",195,196,196,196,197,196,196,196,197,
196,196,196,197,196,196,196,180);
if(a[0]==1 && a[1]==2 && a[2]==3 && a[3]==4 && a[4]==5 && a[5]==6
&&a[6]==7 && a[7]==8 && a[8]==9 && a[9]==10 && a[11]==12 && a[12]==13
won=1;
printf("\n%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n",192,196,196,196,193,196,196,196,193,
196,196,196,193,196,196,196,217);
/***************************************************/
if(won==1) {
break;
/**********************************/
/**********************************/
/****************************************************/
/**********************/
/**********************/
h=getkey();
clrscr();
/****************************************************/
getch();
-----------------------------------------------------------------------------------------------------------------
Solution:
--------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,a[6],even,temp;
clrscr();
for(i=0;i<6;i++) {
scanf("%d",&a[i]);
}
clrscr();
for(i=0;i<6;i++) {
printf("%2d ",a[i]);
for(i=0;i<6;i++) {
for(j=i+1;j<6;j++) {
temp=a[j];
a[j]=a[i];
a[i]=temp;
for(i=0;i<6;i++) {
printf("%2d ",a[i]);
getch();
--------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,r,c,sym;
int a[100][100],b[100][100];
clrscr();
scanf("%d",&r);
scanf("%d",&c);
clrscr();
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
scanf("%d",&a[i][j]);
clrscr();
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
printf("%d ",a[i][j]);
printf("\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
b[j][i]=a[i][j];
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
printf("%d ",b[i][j]);
printf("\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
if(a[i][j]!=b[i][j])
sym=1;
}
if(sym==1)
else
getch();
----------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i,j,r,c,a[100][100];
int norm=0,sum=0;
clrscr();
scanf("%d",&r);
printf("\n\nEnter the number of coloumns: ");
scanf("%d",&c);
clrscr();
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
scanf("%d",&a[i][j]);
clrscr();
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
printf("%2d ",a[i][j]);
printf("\n");
for(j=0;j<c;j++) {
sum=sum+(a[i][j]*a[i][j]);
norm=sqrt(sum);
getch();
----------------------------------------------------------------------------------------------------------------
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,p[]={15,30,28,19,61};
int a[4][5];
clrscr();
for(i=0;i<5;i++) {
printf("%2d ",p[i]);
func(p);
for(i=0;i<5;i++) {
printf("%2d ",p[i]);
for(i=0;i<4;i++) {
for(j=0;j<5;j++) {
scanf("%d",&a[i][j]);
clrscr();
for(i=0;i<4;i++) {
for(j=0;j<5;j++) {
printf("%2d ",a[i][j]);
printf("\n");
printf("\n\nafter shift:\n\n");
for(i=0;i<4;i++) {
func(a[i]);
}
for(i=0;i<4;i++) {
for(j=0;j<5;j++) {
printf("%2d ",a[i][j]);
printf("\n");
getch();
func(int q[5]) {
int a,t1,t2,t3;
t1=q[0];
t2=q[1];
q[0]=q[2];
q[1]=q[3];
q[2]=q[4];
q[3]=t1;
q[4]=t2;
return q[5];
}
----------------------------------------------------------------------------------------------------------
Solution:
----------------------------------------------------------------------
--------
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i,j;
float temp,sd,sum=0,mean,x;
clrscr();
printf("\ndata set: \n\n");
for(i=0;i<15;i++) {
printf("\n");
for(i=0;i<15;i++) {
for(i=0;i<15;i++) {
a[i]=pow((a[i]-mean),2);
x=x+a[i];
temp=x/15;
sd=sqrt(temp);
printf("\n\n\t\tmean= %f\n\t\tstandard deviation = %f\n",mean,sd);
getch();
--------------------------------------------------------------------------------------------------------------
angle
137.4
80.9
0.78
155.2
92.62
0.89
149.3
97.93
1.35
160.0
100.25
9.00
155.6
68.95
1.25
149.7
120.0
1.75
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
float big=0,area;
int sr=0,i;
clrscr();
for(i=0;i<6;i++) {
area=(1.0/2.0)*a[i][0]*a[i][1]*sin(a[i][2]);
if(area>big) {
big=area;
sr=i;
}
getch();
------------------------------------------------------------------------------------------------------------
(q) For the following set of n data points (x, y), compute
the correlation coefficient r,
x
y
34.22
102.43
39.87
100.93
41.85
97.43
43.23
97.81
40.06
98.32
53.29
98.32
53.29
100.07
54.14
97.08
49.12
91.59
40.71
94.85
55.15
94.65
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
{39.87,100.93},
{41.85,97.43},
{43.23,97.81},
{40.06,98.32},
{53.29,98.32},
{53.29,100.07},
{54.14,97.08},
{49.12,91.59},
{40.71,94.85},
{55.15,94.65} };
int i,n=0;
float x2,y2,x,y,x_y,n_x2,n_y2,r;
clrscr();
for(i=0;i<11;i++) {
n++;
n_x2= n * x2;
n_y2= n * y2;
getch();
-------------------------------------------------------------------------------------------------------------
x
y
3.0
1.5
4.5
2.0
5.5
3.5
6.5
5.0
7.5
6.0
8.5
7.5
8.0
9.0
9.0
10.5
9.5
12.0
10.0
14.0
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
{4.5,2.0},
{5.5,3.5},
{6.5,5.0},
{7.5,6.0},
{8.5,7.5},
{8.0,9.0},
{9.0,10.5},
{9.5,12.0},
{10.0,14.0} };
int i,n=0;
float sx,sy,x2,y2,xy,a,b,Y;
clrscr();
for(i=0;i<10;i++) {
sx = sx + data[i][0];
sy = sy + data[i][1];
xy = xy + ( data[i][0] * data[i][1] );
n++;
a = (sy/n) - b*(sx/n);
Y= a + b*sx ;
printf("\n\nvalue of a = %f\n\n",a);
printf("value of b = %f\n\n",b);
printf(" Y = %f \n\n",Y);
getch();
-------------------------------------------------------------------------------------------------------------
(s) The X and Y coordinates of 10 different
points are entered through the keyboard.
Write a program to find the distance of
last point from the first point (sum of
distance between consecutive points).
Solution:
#include<stdio.h>
#include<conio.h>
void main() {
float a[10][2],sx,sy;
int i;
clrscr();
for(i=0;i<10;i++) {
scanf("%f",&a[i][0]);
scanf("%f",&a[i][1]);
clrscr();
for(i=0;i<10;i++) {
sx = sx + a[i][0];
sy = sy = a[i][1];
getch();