TCS
Company
Programming
Arrays
Which program of c andc++ and defination Should prepare for tcs campus
Read Solution (Total 4)
-
- 1. Palindrome for string
#include
#include
main()
{
char a[100], b[100];
printf("Enter the string to check if it is a palindrome
");
gets(a);
strcpy(b,a);
strrev(b);
if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.
");
else
printf("Entered string is not a palindrome.
");
return 0;
}
2. Palindrome number in c
#include
main()
{
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or not
");
scanf("%d",&n);
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
printf("%d is a palindrome number.
", n);
else
printf("%d is not a palindrome number.
", n);
return 0;
}
3. Reverse a string using C programming
#include
#include
main()
{
char arr[100];
printf("Enter a string to reverse
");
gets(arr);
strrev(arr);
printf("Reverse of entered string is
%s
",arr);
return 0;
}
4. Fibonacci Series c language
#include
main()
C programs
9/25/2014 C programs | Aptitude Questions with Answers and Explanations
http://www.campusgate.co.in/2014/09/c-programs.html 2/5
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms
");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-
",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c 0)
{
a=n%10;
sum=sum+(a*a*a);
n=n/10;
}
printf("sum of digits of given number is:%d",sum);
}
4. Write a program to check weather the number is armstrong or not?
main()
{
int n,sum=0,a,t;
printf("enter n");
scanf("%d",&n);
t=n;
while(n>0)
{
a=n%10;
sum=sum+(a*a*a);
n=n/10;
}
if(t==sum)
printf("given number is armstrong");
else
printf("given number is not armstrong");
}
5. Write a program to check weather the number is prime number or not?
main()
{
int n,i=1,f=0;
printf("enter n");
scanf("%d",&n);
while(i - 10 years agoHelpfull: Yes(4) No(2)
- palindrome, prime,swapping( without third variable),fibonacci(recursion),sorting n searching
- 10 years agoHelpfull: Yes(4) No(0)
- Plz send it to me - mesreeya25@gmail.com
- 10 years agoHelpfull: Yes(0) No(0)
- Sir plz can u send me d kv chowdary and tcs papers based on c and aptitude to the id maleykavyashetty@gmail.com
- 6 years agoHelpfull: Yes(0) No(0)
TCS Other Question