tranxit technologies interview questions

 Pattern Printing C Program

#include<stdio.h>

int main()

{

int i,j,k,l;

for(i=1,l=5;i<=9;i=i+2,l--)

{

for(k=0;k<l;k++)

{

printf(" ");

}

for(j=0;j<i;j++)

{

printf("*");

}

printf("\n");

}

return 0;

}


output

     *                                                                                                                             

    ***                                                                                                                            

   *****                                                                                                                           

  *******                                                                                                                          

 *********


Program to Check Palindrome with the user input.

Expected Output: 

Enter a string: radar

radar is a palindrome.


#include<stdio.h>

#include<string.h>

int main()

{

int i,n,m,j;

char s[20];

printf("Enter the string");

scanf("%s",s);

n=strlen(s);

if(n%2==0)

m=n/2;

else

m=(n+1)/2;

for(i=0,j=n-1;i<m;i++,j--)

{

if(s[i]!=s[j])

{

printf("%s is not a palindrome",s);

return 0;

}

}

printf("%s is a palindrome",s);

return 0;

}

Program to Count number of digits in a sentence with the user input.

Expected output: 

Enter a string: 3 apples and 4 oranges cost 120 rupees

Number of digits: 5


#include<stdio.h>

#include<string.h>

int main()

{

int i,n,count=0,j;

char s[20];

printf("Enter the string");

scanf("%s",s);

n=strlen(s);

for(i=0;i<n;i++)

{

if((s[i]>=48)&&(s[i]<=57))

{

count++;

}

}

printf("No of digits is %d",count);

return 0;

}


program to Find the Frequency of a Character.

Expected Output:

Enter a string: This website is awesome.

Enter a character to find its frequency: e

Frequency of e = 4 


#include<stdio.h>

#include<string.h>

int main()

{

int i,n,count=0;

char s[200],c;

printf("Enter the string");

scanf("%[^\n]s",s);

printf("Enter a character");

scanf("%c",&c);

n=strlen(s);

for(i=0;i<n;i++)

{

if(s[i]==c)

{

count++;

}

}

printf("Frequency of character %c is %d",c,count);

return 0;

}


Program to Swap three Elements Using Call by Reference.

Expected output:

Enter a, b and c respectively: 1

2

3

Value before swapping:

a = 1, b = 2, c = 3

Value after swapping:

a = 3, b = 1, c = 2


#include<stdio.h>

void call(int *a,int *b,int *c)

{

int t,t1;

t1=*b;

t=*a;

*a=*c;

*b=t;

*c=t1;

}

int main()

{

int a,b,c;

scanf("%d%d%d",&a,&b,&c);

printf("Before swapping %d %d %d",a,b,c);

call(&a,&b,&c);

printf("After swapping %d %d %d",a,b,c);

return 0;

}

Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post