Wednesday, 28 October 2015

C PROGRAMMING ---POINTER TO ARRARY

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{       clrscr();
    int a[5]={5,6,7,8,9};
    int *p=a,i;
    for(i=0;i<5;i++)
    {    printf("%u\n",(p+i));
        printf("%d\n",*(p+i));
    }
    getch();
}





Wednesday, 14 October 2015

CALCULATION OF STRING LENGTH


1.USING INBUILT FUNCTION

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char  a[10];
    printf("enter the string\n");
    gets(a);
    printf("length of string is %d.",strlen(a));
    getch();
}



2.WITHOU USING INBUILT FUNCTIONS

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    int b=0;
    char  a[10];
    printf("enter the string\n");
    gets(a);
    while(a[b]!='\0')
    {    b++;
    }
    printf("%d",b);
    getch();
}

Tuesday, 13 October 2015

C PROGRAMMING -- SIMPLE INTEREST USING POINTER

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int p,r,t;
printf("enter the principal,rate,time\n");
scanf("%d\t%d\t%d",&p,&r,&t);
float si;
int *a=&p,*b=&r,*c=&t;
float *d=&si;
*d=(*a)*(*b)*(*c)/100;
printf("simple interest=%f",*d);
getch();
}

C PROGRAMMING -- BINARY SEARCH

#include<conio.h>
#include<stdio.h>
void main()
{ int i,last,first,middle,n,search,a[100];
printf("enter the no of elements=\n");
scanf("%d",&n);
printf("enter %d integers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the element to search-\n");
scanf("%d",&search);
first=0;
last=n-1;
middle=(first+last)/2;
while(first<=last)
{
if(a[middle]<search)
first=middle+1;
else if(a[middle]==search)
{
printf("%d found at %d.\n",search,middle+1);
break;
}
else last=middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("not found %d sorry.\n",search);
getch();
}

Wednesday, 7 October 2015

C PROGRAMMING -- MATIX ADDITION

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int c[3][3],a[3][3],b[3][3],i,j;
    printf("enter the 1st matrix =\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {    scanf("%d",&a[i][j]);
    }
    printf("enter the 2nd matrix =\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {    scanf("%d",&b[i][j]);
    }
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {        c[i][j]=a[i][j]+b[i][j];
    }
    for(i=0;i<3;i++)
       {    {    for(j=0;j<3;j++)

            printf("\t%d",c[i][j]);
        }
            printf("\n");
    }
    getch();
}

C PROGRAMMING -- TRANSPOSE OF A MATRIX

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int a[3][3],i,j;
    printf("enter the matrix to transpose=\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {    scanf("%d",&a[i][j]);
    }
    for(i=0;i<3;i++)
       {    for(j=0;j<3;j++)
        {       printf("\t%d",a[j][i]);
        }
        printf("\n");
       }
    getch();
}

C PROGRAMMING -- SUM OF ALL ELEMENTS OF MATRIX

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int sum=0,a[3][3],i,j;
    printf("enter the matrix=\n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
        scanf("%d",&a[i][j]);
        sum=sum+a[i][j];
    }
    printf("\n%d",sum);
    getch();
}