HOME

Tuesday, March 24, 2015

C PROGRAM TO PRINT THE PRIME NUMBERS BETWEEN 1 AND N AS USER CHOICE


#include<stdio.h>
#inlcude<conio.h>
void main()
{
int num,i=1,j,count

clrscr();
printf("Enter Number value To Print Prime Numbers between 1 to Num: ");
scanf("%d",&num);
printf("Prime Numbers upto %d :\n \n",num);

while(i<=num)
{
count=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2) 
printf("%d ",i);
i++;
}
printf("\n\n");


getch(); 
}

Monday, March 23, 2015

MPU 8085 PROGRAM TO SORT THE NUMBER

MVI B 05h
LOOOP: LXI H 2000h
MVI C 05h
LOOP: MOV A M
INX H
CMP M
JNC JUMP
MOV D M
MOV M A
DCX H
MOV M D
INX H
JUMP: DCR C
JNZ LOOP
DCR B
JNZ LOOOP
HLT

C PROGRAM TO SWAP THE NUMBER USING POINTER

#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,*x,*y;
    printf("a=");
    scanf("%d",&a);
    printf("\nb=");
    scanf("%d",&b);
    x=&a;
    y=&b;
    *x=*x+*y;
    *y=*x-*y;
    *x=*x-*y;
    printf("after swapping\n");
    printf("a=%d",*x);
    printf("\na=%d",*y);
}

Friday, March 20, 2015

C PROGRAM TO FIND FIBONACCI SERIES USING RECURSIVE FUNCTION

#include<stdio.h>
#include<conio.h>
int fibo(int n, int a,int b);
main()
{
    int n;
    printf("enter the limit number:\n");
    scanf("%d",&n);
    fibo(n,0,1);
}
int fibo(int n, int a,int b)
{
    if(a>n)
    {
        return 0;
    }
    else
        {
            printf("%d\t",a);
        return fibo(n,b,a+b);
        }


    }

C PROGRAM TO FIND THE FACTORIAL OF GIVEN NUMBER USING RECURSIVE FUNCTION

#include<stdio.h>
#include<conio.h>
int fact(int n);
main()
{
int n;
printf("enter the number n:\n");
scanf("%d",&n);
printf("the factorial %d is %d",n,fact(n));
}
int fact(int a)
{
if(a==1)
{
return 1;
}
else
{
return a*fact(a-1);
}
}

C PROGRAM TO CHECK WEATHER THE GIVEN STRING IS PALINDROME OR NOT

#include<stdio.h>
#include<conio.h>
void main()
{
    char word[10],word1[10];
    printf("enter the string\n");
    gets(word);
    strcpy(word1,word);
    if(strcmp(strrev(word),word1)==0)
    {
        printf("%s  is palindrome\n",word1);
            }
            else
            {
     printf("%s is not palindrome\n",word1);
  }
getch();
}

C PROGRAM USING POINTER TO DISPLAY VALUE AND ADDRESS OF VARIABLE

#include<stdio.h>
#include<conio.h>
void main()
{
    int a=5,*b;
    b=&a;
    printf("the value of a= %d\n",a);
    printf("the address of a is: %d\n",b);
    printf("the value of *b is: %d",*b);
    getch();


}

Thursday, March 19, 2015

C PROGRAM TO TAKE ROLL NO, NAME AND MARK OF STUDENT USING NESTED STRUCTURE

#include<stdio.h>
#include<conio.h>
struct student
{
    int roll;
    char name[20];
    struct marks
    {
        int mark;
    }b;
};
void main()
{
    struct student a;
    printf("enter the roll no, name and mark of student\n");
    scanf("%d%s%d",&a.roll,a.name,&a.b.mark);
    printf("the data you have entered are;\n");
    printf("roll no\tname\tmark\n");
    printf("%d\t%s\t%d",a.roll,a.name,a.b.mark);
}

C PROGRAM TO TAKE NAME, ROLL NO AND MARK OF 5 STUDENT AND DISPLAY IT USING ARRAY IN STRUCTURE

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int roll;
    int mark;
};
void main()
{
    struct student a[5];
    int i;
    for(i=0;i<5;i++)
    {
        printf("enter name %d, roll no and marks\n",i+1);
        scanf("%s%d%d",a[i].name,&a[i].roll,&a[i].mark);
    }
    printf("the data you have entered are:\n");
    printf("name\troll no\tmark\n");
    for(i=0;i<5;i++)
    {
        printf("%s\t%d\t%d\n",a[i].name,a[i].roll,a[i].mark);
    }

}

C PROGRAM TO ENTER NAME, ROLL NO AND MARK AND DISPLAY IT USING STRUCTURE

#include<stdio.h>
#include<conio.h>
struct student
    {
        char name[20];
        int roll;
        int mark;

    };
void main()
{
    struct student a;
        printf("enter the name, roll no and mark\n");
        scanf("%s%d%d",a.name,&a.roll,&a.mark);
        printf("the data you have entered are:\n");
        printf("name\troll\tmark\n");
        printf("%s\t%d\t%d",a.name,a.roll,a.mark);
}

Monday, March 16, 2015

C PROGRAM TO COUNT THE NUMBER OF LETTER PRESENT IN WORD, FIND THE REVERSE OF WORD & CHECK PALINDROME OR NOT. AND DISPLAY THE CONCATENATE BETWEEN FIRST AND TWO WORD


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    char word[20],word1[20],word2[20];
    int n;
    printf("enter the first word\n");
    scanf("%s",word);
    printf("enter the second word\n");
    scanf("%s",word2);
    n=strlen(word);
    strcpy(word1,word);
    printf("the number of letter present in %s is %d\n",word,n);
    printf("the reverse is %s\n",strrev(word1));
    if(strcmp(word,word1)==0)
    {
        printf("%s is palindrome word\n",word);
    }
    else
    {
        printf("%s is not palindrome word\n",word);
    }
    printf("the concatenate of first and second word is %s \n",strcat(word,word2));
    }

FOR MORE PROGRAM CLICK HERE

Saturday, March 14, 2015

C PROGRAM TO PRINT ALL THE PRIME NUMBER UP TO THE LIMIT

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,c,n;
    printf("enter the limit:\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(i==1)
        {
            printf("%d\t",i);
        }
        else
            {
                c=0;
            for(j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                c=c+1;
                }
            }
             if(c==2)
            {
                printf("%d\t",i);
            }

    }
    }
}

PROGRAM TO REVERSE NUMBER & CHECK WEATHER IT IS PALINDROME OR NOT.

#include<stdio.h>
#include<conio.h>
void main()
{
    int rem,n,dig=0,num;
    printf("enter the number n \n");
    scanf("%d",&n);
    num=n;
    while(n>0)
    {
        rem=n%10;
        dig=dig*10+rem;
        n=n/10;
    }
    printf("the reverse is %d\n",dig);
    if(num==dig)
    {
        printf("it is palindrome");
        }
        else
        {
            printf("it is not palindrome");
        }
    }


C PROGRAM TO SORT NUMBER USING BUBBLE SORT METHOD

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,a[10],temp,i,j;
    printf("enter the limit:\n ");
    scanf("%d",&n);
    printf("enter the numbers to be sorted:\n");
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
            }
        }
        printf("the sorted form of number using bubble sort are:\n");
        for(i=0;i<n;i++)
        {
            printf("%d\t",a[i]);
        }
    }

C PROGRAM TO PRINT THE HEART SHAPE PATTERN

heart shape

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int a, b, c;
printf("Enter size of heart(<20): \n");
scanf("%d",&c);
for (a=0; a<c; a++)
{
for (b=0; b<=4*c; b++)
{
int d = sqrt( pow(a-c,2) + pow(b-c,2) );
int e = sqrt( pow(a-c,2) + pow(b-3*c,2) );
if (d < c + 0.5 || e < c +0.5 )
printf("*");
else
printf(" ");
}
printf("\n");
}
for (a = 1; a <= 2*c; a++)
{
for (b=0; b<a; b++)
printf(" ");
for (b=0; b<4*c + 1 - 2*a; b++)
printf("*");
printf("\n");
}
return 0;
}

C PROGRAM TO PRINT FIBONACCI SERIES.

#include<stdio.h>
#include<conio.h>
int fibo(int n, int a,int b);
main()
{
    int n;
    printf("enter the limit number:\n");
    scanf("%d",&n);
    fibo(n,0,1);
}
int fibo(int n, int a,int b)
{
    if(a>n)
    {
        return 0;
    }
    else
        {
            printf("%d\t",a);
        return fibo(n,b,a+b);
        }


    }

C PROGRAM TO INSERT VALUE IN FIXED LOCATION IN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
    int n, a[10],value, position,i;
    printf("enter the limit\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter the number\n");
        scanf("%d",&a[i]);
    }
    printf("enter the position to insert the value\n");
    scanf("%d",&position);
    printf("enter the value to insert \n");
    scanf("%d",&value);
    for(i=n;i>=position-1;i--)
    {
        a[i+1]=a[i];
    }
     a[position-1]=value;
    printf("the numbers are \n");
    for(i=0;i<=n;i++)
    {
        printf("%d\t",a[i]);
    }
}

PROGRAM FOR 2 x 2 MATRIX MULTIPILICATION

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,k,a[2][2],b[2][2],c[2][2];
    printf("enter the matrix A:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",&a[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    printf("enter the matrix B:\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",&b[i][j]);
        printf("\t");
        }
        printf("\n");
    }
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            c[i][j]=0;
            for(k=0;k<2;k++)
            {
                c[i][j]=c[i][j]+a[i][k]*b[k][j];
            }
        }
    }
    printf("The multipication of matrix A and B is :\n");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            printf("%d\t",c[i][j]);
        }
        printf("\n");
    }
}

C PROGRAM FOR MULTIPLICATION TABLE USING RECURSIVE FUNCTION

#include<stdio.h>
#include<conio.h>
int mul(int n,int i);
main()
{
    int n,i=1;
    printf("enter the number\n");
    scanf("%d",&n);
    mul(n,i);
}
int mul(int n,int i)
{
    if(i>10)
    {
        return 0;
    }
    else
    {
        printf("%d*%d=%d\n",n,i,n*i);
        return mul(n,i+1);
    }
}

C PROGRAM TO SWAP THE NUMBER USING CALL BY REFERENCE

#include<stdio.h>
#include<conio.h>
void swap(int *a,int *b)
{
    int c;
    c=*a;
    *a=*b;
    *b=c;
    printf("a=%d\n",*a);
    printf("b=%d\n",*b);
}
void main()
{
    int a,b;
  printf("enter the two number\n");
  scanf("%d%d",&a,&b);
    printf("without swapping\n");
    printf("a=%d\n",a);
    printf("b=%d\n",b);
    printf("after swapping\n");
    swap(&a,&b);
}

C PROGRAM TO REVERSE THE NUMBER USING FUNCTION


#include<stdio.h>
#include<conio.h>
int reverse(int n);
main()
{
    int n;
    printf("enter the number\n");
    scanf("%d",&n);
    printf("the reverse of %d is %d",n,reverse(n));
}
int reverse(int n)
{
    int rem,rev=0;
    while(n>0)
    {
        rem=n%10;
        rev=rev*10+rem;
        n=n/10;
    }
return rev;
}

C PROGRAM TO REVERSE THE NUMBER USING FUNCTION


#include<stdio.h>
#include<conio.h>
int reverse(int n);
main()
{
    int n;
    printf("enter the number\n");
    scanf("%d",&n);
    printf("the reverse of %d is %d",n,reverse(n));
}
int reverse(int n)
{
    int rem,rev=0;
    while(n>0)
    {
        rem=n%10;
        rev=rev*10+rem;
        n=n/10;
    }
return rev;
}