Category Archives: c programming

copy one string to another whithout useing inbuit function

//copy one string to another whithout useing inbuit function
#include<stdio.h>
#include<conio.h>
int i;
void input();
char *process(char *s,char *d);
void output(char *);
void main()
{
clrscr();
input();
getch();
}
void input()
{
char s[20],d[20],*p,*q;
int i;
puts(“enter your source string:”);
gets(s);
puts(“enter your destination string:”);
gets(d);
p=process(s,d);
output(p);
}
char *process(char *s,char *d)
{
int i;
//char *r;
for(i=0;d[i]!=’\0′;i++)
{
s[i]=d[i];
}
s[i]=’\0′;
return s;
}
void output(char *q)
{
puts(q);
}

number is hexa decimal or not

#include<stdio.h>
#include<conio.h>
void main()
{
int i,flag,no,r;
char hexa[20];
clrscr();
printf(“enter your no:”);
scanf(“%s”,&hexa);
for(i=0;hexa[i]!=’\0′;i++)
{
if(hexa[i]>=’a’&&hexa[i]<=’f’||hexa[i]>=’0’&&hexa[i]<=’9′)
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
printf(“hexa decimal”);
else
printf(“not hexa decimal”);
getch();
}

number is magic or not

#include<stdio.h>
#include<conio.h>
void main()
{
int no,sum=0,sum1=0,r;
clrscr();
printf(“enter your no:”);
scanf(“%d”,&no);
for(;no>0;no=no/10)
{
r=no%10;
sum=sum+r;
}
if(sum>9)
{
for(;sum>0;sum/10)
{
r=sum%10;
sum=sum1+r;
}
}
if(sum==1||sum1==1)
printf(“magic”);
else
printf(“not magic”);
getch();
}