​
Showing posts with label Interview Program. Show all posts
Showing posts with label Interview Program. Show all posts

Wednesday, June 26, 2013

Write a program to find whether the given no is perfect square or not ?

Problem:
To find whether the given no is perfect square or not . this so simple to find int and float float value of square root no is same if and only if that no is perfect square, example int sqrt of 2 is 1 and that of float is 1.414,

Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int s1,no;
float s2;
clrscr();
printf("\n enter the no ");
scanf("%d",&no);

s1=sqrt(no);
s2=sqrt(no);
if(s1==s2)
printf("\n the given no %d is square",no);
else
printf("\n the given no %d is not square",no);

getch():
}


Output:

{ Read More }


Tuesday, June 25, 2013

Write a program to find the given string is palindrome or not without using string.h header file?

Problem :
find  the given string is palindrome or not without using string.h header file ,  why this condition is given because without string.h header file we cannot use any function like strlen,strcmp,strcpy,strrev.

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
char a[100],i,j,equal=0,k;
clrscr();
printf("\n enter the string ");
scanf("%s",a);
for(i=0;a[i]!='\0';i++);
for(j=i-1,k=0;a[k]!='\0';j--,k++)
if(a[j]==a[k])
equal++;
if(equal==i)
printf("\n the %s is palindrome",a);
else
printf("\n the %s is not palindrome",a);
getch();
}



{ Read More }


Write a program to Swap two no without using any third variable ?

Problem:
 Swap the 2 number without using any third variable .

Solution:

#include<conio.h>
#include<stdio.h>

void main()
{
int a, b;
clrscr();
printf("\n enter the two no ");
scanf("%d%d",&a,&b);
printf("before swape \n A=%d   B=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swape \n A=%d   B=%d",a,b);
getch();
}


Output:

{ Read More }


Write a Program to find high common factor (HFC) three no ?

Problem :
 Find Greatest Common divisor for given three no, ex125,25 and 15 HFC is 5

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int no1,no2,no3,temp,flag=0;
clrscr();
printf("\n enter the two no decesending order ");
scanf("%d%d%d",&no1,&no2,&no3);
start:
while(no2!=0)
{
 temp=no1%no2;
 no1=no2;
 no2=temp;
}
if(flag==0)
{
flag=1;
if(no1<no3)
{
no1=no3;
no2=no1;
}
else
{
no1
goto start;
}
printf("\n the highest comman factor is %d",no1);
getch();
}


Output:








if any doubt, post it on comment
{ Read More }


Write Program to find Highest common factor (HFC) of two no ?

Problem :
 Find Greatest Common divisor for given two no, ex 22 and 33 HFC is 11

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int no1,no2,temp;
clrscr();
printf("\n enter the two no decesending order ");
scanf("%d%d",&no1,&no2);
while(no2!=0)
{
 temp=no1%no2;
 no1=no2;
 no2=temp;
}
printf("\n the highest comman factor is %d",no1);
getch();
}

Output:










if any doubt , post it on comment
{ Read More }


Write a Program to find no of words in given line ?

Problem:
Write a program to no of words in given line , ex give line is "Welcome you All" and result should be printed as 3

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
char a[100]="this is c language ",i,j,count=0,need_word=1,isalphabet;
clrscr();
printf("\n%s",a);
for(i=0;a[i]!='\0';i++);
for(j=0;j<i;j++)
{
if((a[j]>='a'&&a[j]<='z')||(a[j]>='A'&&a[j]<='B'))
isalphabet=1;
else
isalphabet=0;
if(isalphabet)
{
if(need_word)
{
count++;
need_word=0;
}
}
else
need_word=1;
}

printf("\nthe length of the string is %d",count);
getch();
}


Output:















if any doubt in above coding , please post it
{ Read More }


Monday, June 24, 2013

Write a program to find perfect square number near given number?

Probelm:
To find the perfect square no for given nu  , example give no 160  then it should print near perfect square is 169

Solution:

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int i,j,n,avg1;
float avg2;
clrscr();
printf("enter the no");
scanf("%d",&n);
i=n;
j=n;
while(1)
{
i++;
j--;
avg1=sqrt(i);
avg2=sqrt(i);
if
(avg1==avg2)
{
printf("the near perfect square is %d ",i);
break;
}
avg1=sqrt(j);
avg2=sqrt(j);
if(avg1==avg2)
{
printf("the near perfect square is %d ",j);
break;
}
}
getch();
}

Output:
 
{ Read More }


Write a program to find the length of the string (without using strlen function) ?

Problem:
To find the length of the given string without using any strlen function

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
char a[100],i,j;
clrscr();
printf("\nenter the string without space");
scanf("%s",a);
for(i=0;a[i]!='\0';i++);
printf("the length of the string is %d",i);
getch();
}


Output:
 


{ Read More }


Write a program to print string without any special character?

Problem:
You have to print the given string without any special character , example  string CO#M&*PUT^ER should be printed as COMPUTER

Sloution:

#include<stdio.h>
#include<conio.h>

void main()
{
char a[100],i,j;
clrscr();
printf("\nenter the string without space");
scanf("%s",a);
for(i=0;a[i]!='\0';i++);
for(j=0;j<i;j++)
if((a[j]>='a'&&a[j]<='z')||(a[j]>='A'&&a[j]<='B'))
printf("%c",a[j]);
getch();
}

Output:

{ Read More }


Write a program to convert Decimal to Binary or Octal or Hexadecimal with menu option?

Problem:
To convert the given decimal no into binary or octal or hexadeciaml with menu option , if user enter the base 8 it should be converted into octal

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j,base;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\n enter the base \nBinary--->2\nOctal--->8\nHexadecimal--->16");
scanf("%d",&base);
while(a!=0)
{
data[i]=a%base;
i++;
a=a/base;
}
for(i--;i>=0;i--)
{
j=data[i];
if(j<=9)
printf("%d",intex[j]);
else
printf("%c",intex[j]);
}
getch();
}

Output:


{ Read More }


Write a program to convert Decimal to Hexadecimal?

Problem: 
To convert the given decimal no into Hexadecimal without using in build function ,Example 26  shoule printed as 32

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\nthe %d to binary is ",a);

while(a!=0)
{
data[i]=a%16;
i++;
a=a/16;
}
for(i--;i>=0;i--)
{
j=data[i];
if(j<=9)
printf("%d",intex[j]);
else
printf("%c",intex[j]);

}
getch();
} 


Output:

{ Read More }


Write a program to convert Decimal to Octal?

Problem:

To convert the given decimal no into octal without using in build function ,Example 26  shoule printed as 32

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1,2,3,4,5,6,7},data[100],i=0,j;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\nthe %d to octal is ",a);

while(a!=0)
{
data[i]=a%8;
i++;
a=a/8;
}
for(i--;i>=0;i--)
{
j=data[i];
printf("%d",intex[j]);
}
getch();
}


Output:


{ Read More }


Write a program to convert Decimal to Binary?

Problem
To convert the given decimal no into binary without using in build function , exampla 11 to printed as 1011

Solotion
#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,intex[]={0,1},data[100],i=0,j;
clrscr();
printf("\n enter the no ..");
scanf("%d",&a);
printf("\nthe %d to binary is ",a);

while(a!=0)
{
data[i]=a%2;
i++;
a=a/2;
}
for(i--;i>=0;i--)
{
j=data[i];
printf("%d",intex[j]);
}
getch();
}



Output


{ Read More }


Write a program to convert Fahrenheit to degree?

Problem: 
convert the value in Fahrenheit into degree  , and relationship between degree and Fahrenheit is D=(F-32)*1.8

solution:

#include<stdio.h>
#include<conio.h>

void main()
{
float deg,frn;
clrscr();
printf("enter the Fahrenheit");
scanf("%f",&frn);
deg=(frn-32)/1.8;
printf("the %.2fF---> %.2f deg",frn,deg);
getch();
}


Output

{ Read More }


Write a program to convert degree to Fahrenheit?

Problem: 
convert the value in degree into Fahrenheit , and relationship between degree and Fahrenheit is
F= D*1.8+32

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
float deg,frn;
clrscr();
printf("enter the degree");
scanf("%f",&deg);
frn=deg*1.8+32;
printf("the %.2fdeg---> %.2f F",deg,frn);
getch();
}


Output :

{ Read More }


Write a program to find 2nd or 3rd or 4th or Nth greatest no without using sorting algorithm?

Problem:
 Find asked greatest no in the given array without using sorting algorithm, example the array is 1,2,4,5 ,6,5,7
asked greatest no is 3 then it should print 5, if it asked 2nd greatest no then it should print 6.
Solution

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,no[100],n,in,high=0;
clrscr();
printf("enter the no of no");
scanf("%d",&n);
printf("enter the no one by one");
for(i=0;i<n;i++)
scanf("%d",&no[i]);
printf("enter the which high no you need");
scanf("%d",&in);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(no[i]>no[j])

high++;
}
if(high==n-in)
{
break;
}
high=0;
}
printf("the %d big no is %d",in,no[i]);
getch();
}

Output
 
{ Read More }


Write a program to print the sum of the two no in reverse order ?

Problem 
    Find the sum of two no and print their result in reverse order .ex 12+12=24 should be printed as 42
solution

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,sum,rsum=0,n;
clrscr();
printf("enter the no1 and no2");
scanf("%d%d",&a,&b);
sum=a+b;
while(sum!=0)
{
n=sum%10;
rsum=rsum*10+n;
sum=sum/10;
}

printf("the near perfect square is %d ",rsum);
getch();
}

Output

{ Read More }


Write a Program to find given no is palindrome or not ?

//Palindrome Program
#include<stdio.h>
#include<conio.h>

void main()
{
int n,no,rno=0,dno;
clrscr();
printf("enter the no");
scanf("%d",&no);
dno=no;
while(no!=0)
{
n=no%10;
rno=rno*10+n;
no=no/10;
}
if(dno==rno)
printf("the %d is palindrome ",dno);
else
printf("the %d is not palindrome",dno);
getch();
}
Output













What is Palindrome number ?
  The no is said to palindrome whose direct view and mirror view are same, example take 121 , whose mirror image is 121  so 121 is palindrome.

if have any doubt , post it on comment
{ Read More }