Saturday, October 22, 2011

c Technical basics



Hi Blog readers,
I am sabari, computer science engineer. Here I would like to Share some of my Interview preparation Question you may worked out (compile and run) you will come to know some interesting facts on C Basics,
//No of Args
#include
void main()
{                     
int n,a,b,c;
printf("ENter the 3 nos");
n=scanf("%d%d%d",&a,&b,&c);
printf("No of Args:%d",n);
getch();
}
//Ex2 No of Args
#include
#include
int main()
{
int n,a,b,c;
clrscr();
printf("ENter the 3 nos");
n=scanf("%d%d%d",&a,&b,&c);
printf("No of Args:%d",n);
n=printf(printf("First second"););
printf("No of Args:%d",n);
getch();
return 0;
}

//Digit sum(145),1+4+5=10=1+0=1;
#include
#include
void main()
{
 int n;
 clrscr();
 printf("Enter your no");
 scanf("%d",&n);
 n=n%9;
 if(n!=0)
 {
   printf("the digit sum is %d",n);
  }
  else
  {
   printf("the digit sum is %d",9);
   }
 }
 //Input formatting
 #include
#include

void main()
{
                float x = 12.34567;                              /* The keyword `float' declares the number x
                                                                                                                                   to be a real number. */
                clrscr();

                printf("%f\n", x);
                printf("%8.5f\n", x);
                printf("%8.3f\n", x);
                printf("%-8.3f\n", x);
                printf("%9.2e\n", x);            /* printing real number in exponential form */
                printf("%12.4e\n", x);
                printf("%5e\n", x);
                printf("%8.3f\n", -x);

                getch();
}
#include
#include
int main()
{
int n,f;
clrscr();
printf("Enter the NO:");
scanf("%d",&n);
f=fact(&n);
printf("factorial of given is:%d",f);
getch();
return 0;
}
int fact(int *n)
{
int fact=1,i;
 if(*n==0||*n==1)
   return 1;
  else
{
for(i=1;i<=*n;i++)
 {
   fact=fact*i;
 }
 return fact;
}
 
}
//summation
#include
#include
int main()
{
int n,f;
clrscr();
printf("Enter the NO:");
scanf("%d",&n);
f=sum(&n);
printf("summation of given is:%d",f);
getch();
return 0;
}
int sum(int *n)
{
int sum=0,i;
/*
 if(*n==0||*n==1)
   return 1;
  else
  */
{
for(i=0;i<=*n;i++)
 {
   sum=sum+i;
 }
 return sum;
}
 
}
//swapping ( Four different Techniques)
#include
void main()
{
int a,b;
printf("welcome TO swap\nEnter your two nos:\n");
scanf("%d%d",&a,&b);
swap(a,b);
swap(&a,&b);
printf("The swappwe3d nos:%d%d",a,b);
swapt(&a,&b);
printf("The swappwe3d nos:%d%d",a,b);
swapBit(&a,&b);
printf("The swappwe3d nos:%d%d",a,b);
printf("The swappwe3d nos:%d%d",a,b);
swap1(a,b);
getch();
}
//call by value
int swap(int x,int y)
{
 int t;
 t=x;
 x=y;
 y=t;
 printf("The swappwe3d nos:%d%d",x,y);
}
//call by value
int swap1(int x,int y)
{
 x=(x+y)-(y=x);
 printf("The swappwed nos:%d%d",x,y);
}
//call by Ref
int swap(int *x,int *y)
{
 int t;
 t=*x;
 *x=*y;
 *y=t;

}
int swapt(int *x,int *y)
{
 //int t;
 *x=*x+*y;
 *y=*x-*y;
 *x=*x-*y;

}
int swapBit(int *x,int *y)
{
 //int t;
 *x=*x+*y;
 *y=*x-*y;
 *x=*x-*y;

}
//text compresion
#include
#include
void main()
{
FILE *fp,*fd;
char a,b;
int i=1,j;
clrscr();
gotoxy(10,15);
fp=fopen("intxt.txt","r");
fd=fopen("outtxt.txt","w");
fscanf(fp,"%c",&b);
while(!feof(fp))
{
fscanf(fp,"%c",&a);
if(b==a)
{
i++;
}
else
{
if(i>=2)
{
printf("@");
fprintf(fd,"@");
printf("%c%d",b,i);
i=1;
}
else
{
for(j=0;j
{
printf("%c",b);
fprintf(fd,"%c",b);
} i=1;
}}
b=a;
}
if(i>2)
{
printf("@");
fprintf(fd,"%c",a);
i=0;
}
getch();
}

No comments:

Post a Comment