Resources » Articles/Knowledge Sharing » My Interview Experience

C Programs Frequently Asked In Interviews.


Posted Date: 24-Jul-2008  Last Updated:   Category: My Interview Experience    
Author: Member Level: Gold    Points: 4



-Write a C Program to join two strings? (eg. Input “hari” &”123”
output=”hari123”) ?

int main()
{
char str1[10], str2[10];
printf("Enter the first string = ");
scanf("%s", str1);
printf("Enter the second string = ");
scanf("%s", str2);
printf("Concatenation of two strings = %s", strcat(str1, str2));
return(0);
}



-Write a program to find highest of five numbers entered by user?


int main()
{
int i, a[5], max;
printf("Enter the 5 numbers = ");
for (i=0; i<5; i++)
scanf("%d", &a[i]);
max = a[0];
for (i=1; i<5; i++)
{
if (max < a[i])
{
max = a[i];
}
}
printf("\nMaximum of 5 numbers = %d", max);
return(0);
}



-Enter a string & write a program to obtain reverse of string. Determine whether
the original and reverse strings are equal?


int main()
{
char orgstr[10], revstr[10];
int i;
printf("Enter a string = ");
scanf("%s", str);

strcpy(revstr, orgstr);
for (i=0; i {
char c = revstr[i];
revstr[i] = revstr[strlen(revstr)-i-1];
revstr[strlen(revstr)-i-1] = c;
}

printf("\nReverse of the string = %s", revstr);

if (strcmp(orgstr, revstr) == 0)
printf("The Original & Reverse strings are equal\n");

else
printf("The Original & Reverse strings are not equal\n");

return(0);
}



-Write a program to display Fibonacci series upto 70?

int main()
{
int fibonacci(int n);
int i;
printf("Fibonacci Series upto 70 is :");
for (i=1; i<11; i++)
{
printf ("%d ", fibonacci(i));
}
printf("\n");
return(0);
}

int fibonacci(int n)
{
if (n == 1 n == 2)
{
return 1;
}
else
return fibonacci(n-1) + fibonacci(n-2);
}



-Write a program to count number of words from a given sentence?

int main()
{
char sentence[100];
int i, count = 0;
printf("Enter a Sentence : \n");
gets(sentence);
for (i=0; i {
if (isspace(sentence[i]))
{
count++;
}
}
printf("Number of words in the sentence = %d", ++count);
return(0);
}


-Write a program to interchange the contents two variables?

int main()
{
int a, b;
int temp;

printf("Enter value of a & b = ");
scanf("%d %d", &a, &b);

temp = a;
a = b;
b = temp;

printf("\nValues of after interchanging a & b\n");
printf("a = %d b = %d\n\n", a, b);


return(0);
}


Reference: http://uttambpt.blogspot.com


Did you like this resource? Share it with your friends and show your love!




Responses to "C Programs Frequently Asked In Interviews. "
Author: T Syed Rizwan    03 Mar 2011Member Level: Gold   Points : 1
Hi,

Your contribution of frequently asked C interview questions was good. You have given all the important basic programs.

Hope it will be useful for persons who are attending software company interviews. I request you to contribute more questions like this which will help many in future.

Regards,
Rizwan.



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.