Thursday, 24 September 2015

C PROGRAMMING -- LINEAR SEARCH

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int a[5],i,n,flag=0,c=0;

printf("enter the array\n");
for(i=0;i<5;i++)
{ scanf("\t%d",&a[i]);
}
printf("enter the searching element=");
scanf("%d",&n);
for(i=0;i<5;i++)
{ if(a[i]==n)
{ flag=1;
c++;

}
}
if(flag==1)
{ printf("element found !! %d times",c);
}
else
{ printf("element not found");
}
getch();
}

C PROGRAMMING -- NUMBER PATTERN IN MATRIX

#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j,k=1;
    for(i=0;i<5;i++)
    {    for(j=0;j<=i;j++)
    {    printf("\t%d",k);
        k++;
        }
        printf("\n\n");
     }


    getch();
}

Wednesday, 23 September 2015

C PROGRAMMING -- STAR PATTERNS

1.
 
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j;
    for(i=0;i<5;i++)
    {    for(j=0;j<=i;j++)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}

2.
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j;
    for(i=0;i<5;i++)
    {    for(j=4;j>=i;j--)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}


3.
#include<conio.h>
#include<stdio.h>
void main()
{       clrscr();
    int i,j,k;
    for(i=0;i<5;i++)
    {    for(k=0;k<4-i;k++)
        {    printf("\t-");
        }
        for(j=0;j<=i;j++)
        {    printf("\t*");
        }
        printf("\n\n");
     }


    getch();
}
 

C PROGRAMMING -- MINIMUM OF ALL THE EMENTS OF A 3*3 MATRIX

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


    getch();
}

C PROGRAMMING -- SUM OF ALL ELEMENTS OF A MATRIX OF 3*3

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

C PROGRAMMING --SUM OF DIAGONAL ELEMENTS IN MATRIX OF 3*3

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

C PROGRAMMING -- GEOMETRIC SERIES

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{       clrscr();
int a,r,i,n,an;
printf("enter the common ratio= \tenter first term=\tenter no of terms required=\n");
scanf("%d%d%d",&r,&a,&n);

for(i=1;i<=n;i++)
{ an=a*pow(r,i-1);
printf("\t%d\t",an);
}
getch();
}

Tuesday, 22 September 2015

C PROGRAMMING -- SMALLEST NO AMONG 10 NUMBERS

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int a[10],i,min;
printf("enter 10 numbers=\n");
for(i=0;i<10;i++)
{ scanf("%d",&a[i]);
min=a[0];
{ if(a[i]<min)
{ min=a[i];
}
}
}
printf("smallest no=%d",min);
getch();
}

C PROGRAMMING -- SUM OF 10 NOS USING ARRAY

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

Saturday, 19 September 2015

C PROGRAMMING-- ARITHMETIC PROGRESSIONS

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int n,i,a,d,c;
printf("enter first term=\tenter common difference=\tenter no of terms=\t");
scanf("\t%d\t%d\t%d",&a,&d,&i);
for(n=1;n<=i;n++)
{ c=a+(n-1)*d;
printf("%d\t",c);
}
getch();
}

Thursday, 17 September 2015

C PROGRAMMING-- FIBONACCI USING FUNCTION

#include <stdio.h>
#include <conio.h>
void fibo(int);
void main()
{
    clrscr();
    int n;
    printf("enter the no of terms=\n");
    scanf("%d",&n);

    fibo(n);
    getch();
}
void fibo(int x)
{            int i,a=0,b=1,output;
         printf("%d\t%d",a,b);
        for(i=2;i<x;i++)
           {    output=a+b;
            printf("\t%d",output);
            a=b;
            b=output;
           }
}

C PROGRAMMING-- FIBONACCI SERIES

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int n,i,a=0,b=1,output;
    printf("enter the no of terms=");
    scanf("%d",&n);
    printf("%d\t%d",a,b);

    for(i=2;i<n;i++)
    {    output=a+b;
        printf("\t%d",output);
        a=b;
        b=output;
     }
     getch();
}


Wednesday, 16 September 2015

C PROGRAMMING-- PALINDROME

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int n,r,rev=0,n1;
printf("enter the no.=\n");
scanf("\n%d",&n);
n1=n;
while(n>0)
{ r=n%10;
n=n/10;
rev=rev*10+r;}

printf("reverse=%d\n\n",rev);
if(n1==rev)
{ printf("\nPALLINDROME!!!");
}
else
{ printf("\nOOPS!!! NOT PALLINDROME");
}
getch();
}

C PROGRAMMING-- FACTORIAL USING RECURSIVE FUNCTION

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{ clrscr();
int n,f;
printf("enter the no.\n");
scanf("%d",&n);
f=fact(n);
printf("FACTORIAL=%d\n",f);
getch();
}
int fact(int x)
{       int y;
if(x==0||x==1)
{ return 1;
}
else
{ y=x*fact(x-1);
}       return y;
}

Tuesday, 15 September 2015

C PROGRAMMING-- FACTORIAL

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();
int i,n,f=1;
printf("enter the no.=\n");
scanf("\n%d",&n);
for(i=1;i<=n;i++)
{ f=f*i;
}
printf("factorial=%d\n",f);
getch();
}

C PROGRAMMING-- ADDITION USING FUNCTIONS

1. without returning any value.
#include<stdio.h>
#include<conio.h>
void add(int,int);
void main()
{ clrscr();
        int a,b;
printf("enter the numbers=\n");
scanf("%d\n%d",&a,&b);

       add(a,b);
getch();
}
void add(int x,int y)
{ printf("addtion=%d\n",x+y);
}


2.  with returning value
#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{ int a,b;
printf("enter the numbers=\n");
scanf("%d\n%d",&a,&b);


printf("addition=%d",add(a,b));


getch();
}
int add(int x,int y)
{ return x+y;
}


C PROGRAMMING-- CALL BY ADDRESS ADDITION FUNCTION

#include<stdio.h>
#include<conio.h>
int add(int*,int*);
void main()
{       clrscr();
int a,b,c;
printf("enter the nos=\n");
scanf("%d\n%d",&a,&b);
c=add(&a,&b);
printf("sum=\n%d",c);
getch();
}
add(int *x,int *y)
{ int *z;
*z=*x+*y;
return *z;
}

Sunday, 13 September 2015

C PROGRAMMING-- REVERSE OF NO.

#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int n,r;
printf("enter the no.=\n");
scanf("\n%d",&n);
printf("reverse=\n");
while(n>0)
{ r=n%10;
n=n/10;
printf("%d",r);
}
getch();
}

C PROGRAMMING-- SUM OF DIGITS

#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int r,s=0,n;
printf("Enter the no=\n");
scanf("\n%d",&n);
while(n>0)
{ r=n%10;
n=n/10;
s=s+r;
}
printf("sum of digits=%d\n",s);

getch();
}

C PROGRAMMING-- SIZE OF

#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int a,d,e,f;
float b;
char c,ch;
printf("integer-a\nfloat-b\ncharacter-c\nENTER CHOICE=\n");
scanf("%c",&ch);
switch(ch)
{ case 'a': d=sizeof(a);
printf("size=%d\n",d);
break;
case 'b': e=sizeof(b);
printf("size=%d\n",e);
break;
case 'c': f=sizeof(c);
printf("size=%d\n",f);
break;
default:printf("wrong input\n");
}
getch();
}

C PROGRAMMING-- ASCII CODES

#include<stdio.h>
#include<conio.h>
void main()
{       clrscr();

char a;
printf("enter the character=\n");
scanf("%c",&a);
printf(" ASCII CODE=%d",a);
getch();
}

C PROGRAMMING-- ARMSRONG NO.


#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int n,r,x,s=0,n1;
printf("ENTER THE NO.=\n");
scanf("\n%d",&n);
n1=n;
while(n>0)
{ r=n%10;
n=n/10;
x=r*r*r;
s=s+x;
}
if(n1==s)
{  printf("ARMSTRONG NO.!!!\n");
}
else
{
printf("not a armstrong no.=\n");
}
getch();
}

HOW TO COPY TO TURBO C++

Open a new file in turbo c++, save it blank with any name (say abc.cpp).then go to bin folder of turbo c++. open your file (abc.cpp) using a text editor. paste your code there and then save it. relaunch tc and then open your file.

C PROGRAMMING --TABLE OF A NO.

USING FUNCTION

#include<stdio.h>
#include<conio.h>
void table(int);
void main()
{ clrscr();
int n;
printf("enter the no.=");
scanf("%d",&n);
table(n);
getch();
}
void table(int x)
{ int i,t;
for(i=1;i<=10;i++)
{ t=x*i;
printf("%d\n",t);

}
}

WITHOUT USING FUNCTION

#include<stdio.h>
#include<conio.h>
void main()
{ int i,n;
clrscr();
printf("enter the no.=");
scanf("%d",&n);
for(i=n;i<=(n*10);i=i+n)
{ printf("%d\n",i);
}
getch();

}