Showing posts with label advance C programming. Show all posts
Showing posts with label advance C programming. Show all posts
Friday, November 11, 2011
How to check a number palindrome or not in C
How to check a number palindrome or not in C
#include<stdio.h>
void main(){
int n,r,sum=0,temp;
printf("Please enter a number: ");
scanf("%d",&n);
temp=n;
while(n){
r=n%10;
n=n/10;
sum=sum*10+r;
}
if(temp==sum)
printf("%d is a palindrome number",temp);
else
printf("%d is not a palindrome number",temp);
}
How to generate armstrong number with in a range
How to generate armstrong number with in a range
#include<stdio.h>
void main(){
int num,r,sum,temp;
int min,max;
printf("Enter the left range: ");
scanf("%d",&min);
printf("Enter the right range: ");
scanf("%d",&max);
printf("Armstrong numbers in given range are: ");
for(num=min;num<=max;num++)
{
temp=num;
sum = 0;
while(temp!=0){
r=temp%10;
temp=temp/10;
sum=sum+(r*r*r);
}
if(sum==num)
printf("%d ",num);
}
}
How to generate perfect number with in a range
How to generate perfect number with in a range
#include<stdio.h>
void main(){
int n,i,sum;
int min,max;
printf("Enter the left range: ");
scanf("%d",&min);
printf("Enter the right range: ");
scanf("%d",&max);
printf("Perfect numbers in given range is: ");
for(n=min;n<=max;n++){
i=1;
sum = 0;
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d ",n);
}
}
Sunday, November 6, 2011
How to Use Mouse in C language
How to Use Mouse in C language
union REGS i,o;
void initmos()
{
i.x.ax=0;
int86(0x33,&i,&o);
}
void space(int size)
{
int i;
int prevx,prevy;
prevx=wherex();
prevy=wherey();
gotoxy(prevx,prevy);
textattr(112);
for(i=1;i<=size;i++)
{
cprintf(" ");
}
gotoxy(prevx,prevy);
}
void showmos()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void getmos(int *x,int *y,int *b)
{
i.x.ax=3;
int86(0x33,&i,&o);
*b=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
union REGS i,o;
void initmos()
{
i.x.ax=0;
int86(0x33,&i,&o);
}
void space(int size)
{
int i;
int prevx,prevy;
prevx=wherex();
prevy=wherey();
gotoxy(prevx,prevy);
textattr(112);
for(i=1;i<=size;i++)
{
cprintf(" ");
}
gotoxy(prevx,prevy);
}
void showmos()
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void getmos(int *x,int *y,int *b)
{
i.x.ax=3;
int86(0x33,&i,&o);
*b=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
Encrypt and Decrypt folders and files using C language
Encrypt and Decrypt folders and files using C language
#include<stdio.h>
#include<conio.h>
#include<string.h>
void crypt(char arr1[],int ch)
{
char arr2[9];
int len,stat;
len=strlen(arr1);
if(len<=7)
{
strcpy(arr2,arr1);
arr2[len]=255;
arr2[len+1]=NULL;
if(ch==1)
{
stat=rename(arr1,arr2);
}
if(ch==2)
{
stat=rename(arr2,arr1);
}
if(stat==0)
{
printf("Operation successfull");
}
else
{
printf("Procedure fail");
}
}
else
{
printf("\nEnter folder name less equal to 7");
}
}
void main()
{
char arr1[9];
int ch;
clrscr();
printf("1.Encrypt\n2.Decrypt\n¯");
scanf("%d",&ch);
printf("Enter the old folder name:");
scanf("%s",arr1);
crypt(arr1,ch);
getch();
}
Saturday, November 5, 2011
Execute DOS commands in C language
This is the sample code for how to execute DOS commands in C language
#include<conio.h>
#include<stdio.h>
#include<process.h>
void main()
{
system("dir"); // use your desired command instead of "dir" command
getch();
}
Caps Lock on and Off operation ( Assembly codes)
This is a sample code for hardware operations using C language
void main()
{
asm{
push ds
mov ax,40h
mov ds,ax
mov cl,[17h]
and cl,64
cmp cl,0
jnz l
mov cl,[17h]
or cl,64
mov [17h],cl
jmp end
}
l:
asm{
mov cl,[17h]
and cl,191
mov [17h],cl
}
end:
asm pop ds
}
void main()
{
asm{
push ds
mov ax,40h
mov ds,ax
mov cl,[17h]
and cl,64
cmp cl,0
jnz l
mov cl,[17h]
or cl,64
mov [17h],cl
jmp end
}
l:
asm{
mov cl,[17h]
and cl,191
mov [17h],cl
}
end:
asm pop ds
}
Bubble sort using C laguage
#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10],i,temp,j;
clrscr();
printf("Enter the numbers:");
for(i=0;i<=9;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<=9;i++)
{
for(j=i+1;j<=9;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(i=0;i<=9;i++)
{
printf("\n");
printf(" %d",arr[i]);
}
getch();
}
Binary Search in C language
Binary Search in C language
#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10]={34,56,12,345,2,65,89,34,5,12};
int i,j,temp;
int beg=0,end=9,mid,item;
clrscr();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\n");
for(i=0;i<10;i++)
{
printf(" %d",arr[i]);
}
printf("\nEnter number to find ");
scanf("%d",&item);
while(beg<=end)
{
mid=int((end+beg)/2);
if(item==arr[mid])
{
printf("\nNumber is present\nLocation=%d",mid);
break;
}
else
{
if(arr[mid]>item)
{
beg=mid+1;
}
else
{
end=mid-1;
}
}
}
if(beg>end)
{
printf("\nNumber is not present....");
}
getch();
}
#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10]={34,56,12,345,2,65,89,34,5,12};
int i,j,temp;
int beg=0,end=9,mid,item;
clrscr();
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\n");
for(i=0;i<10;i++)
{
printf(" %d",arr[i]);
}
printf("\nEnter number to find ");
scanf("%d",&item);
while(beg<=end)
{
mid=int((end+beg)/2);
if(item==arr[mid])
{
printf("\nNumber is present\nLocation=%d",mid);
break;
}
else
{
if(arr[mid]>item)
{
beg=mid+1;
}
else
{
end=mid-1;
}
}
}
if(beg>end)
{
printf("\nNumber is not present....");
}
getch();
}
Assembly language coding using C
This is a very simple code written in C language. You can read this program and can get help of, how to execute assembly codes in C compiler. This simple code will compare whether you have entered 1 or 2 or 3
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2;
clrscr();
printf("Enter a number:");
scanf("%d %d",&n1);
asm mov ax,n1;
asm cmp ax,1;
asm jnz l1;
printf("1");
l1:
asm cmp ax,2;
asm jnz l2;
printf("2");
l2:
asm cmp ax,3;
asm jnz l3;
printf("3");
l3:
getch();
}











