C interview Programs for TCS

Answer Posted / subrahmanyam kesana...........

C Programmes



******* Fibonacci series **********

#include<stdio.h>
main()
{
Int n1=0,n2=1,n,counter,fib;
Printf(“enter the length of fibonacc series”);
Scanf(“%d”,&n);
Printf(“the Fibonacci series is:”);
Printf(“%d%d”,n1,n2);
for(counter=1;counter<=n-2;counter++)
{
Fib=n1+n2;
Printf(“%d”,fib);
N1=n2;
N2=fib;
}
}


******* To generate prime number **********

#include<stdio.h>
main()
{
int n,I,j,b;
printf(“enter the value of n”);
scanf(“%sd”,&n);
for(i=1;i<=n;i++)
{
b=0;
for(j=1;j<=i;j++)
{



If(i%j==0)
{
b=b+1;
}
}
If(b===2)
{
Printf(“%d”,i);
}
}
}




*********Calculating sum of the digits********

#include<stdio.h>
main()
{
int n,k,sum=0;
printf(“enter the number that is to be added”);
scanf(“%d”,&n);
while(n!=0)
{
K=n%10;
Sum=sum+k;
N=n/10;
}
Printf(“sum of digits is%d”,sum);
}




********To reverse a number ********

#include<stdio.h>
main()
{
int n,k,rev=0;
printf(“enter the number that is to be reversed”);
scanf(“%d”,&n);
while(n!=0)
{
K=n%10;
rev=rev*10+k;
N=n/10;
}
Printf(“reverse number is%d”,rev);
}



*********Factorial number********

#include<stdio.h>
main()
{
Int num,factorial=1;
Printf(“enter the number”);
Scanf(“%d”,&num);
While(num>0);
{
Factorial=factorial*num;
Num=num-1;
}

Printf(“Factorial is%d”,factorial);
}



********Finding even & odd numbers********

#include<stdio.h>
main()
{
Int n,I;
printf(“enter the values of n”);
scanf(“%sd”,&n);
for(i=1;i<=n;i++)
{
If(i%2==0)
Printf(“%d is even”);
Else
Printf(“%d is odd”);
}
}


********Palindrome number********

include<stdio.h>
main()
{
Int n,n1,r,sum=0;
printf(“enter the number”);
scanf(“%sd”,&n);
n1=n;
while(n>0)
{
r=n%10;
sum=sum*10+k;
n=n/10;
}
If(n1==sum)
Printf(“it is palindrome”);
else
Printf(“it is not a palindrome”);

}



********Armstrong number********

#include<stdio.h>
main()
{
Int n,n1,r,sum=0;
printf(“enter the number”);
scanf(“%sd”,&n);
n1=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
If(n1==sum)
Printf(“it is Armstrong number”);
else
Printf(“it is not a Armstrong number”);

}


Is This Answer Correct ?    17 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is difference between uv and visible spectroscopy and how to differentiate the drug compounds in uv visible region

1601


HI SIR I WANT PREVIOUS QUESTION PAPER OF HPCL I M CHEMICAL ENGG.

1949


how did you celebrate your last birthday?

1281


i want the sample placement paper of goldman sachs urgently. please send it to me

3931


what you will do when you struck in traffic ?

1057






Hi.. Guys Im pranitha, presently im working in a organisation & im look for job at MNC's like DELL, Delloitte, Bank of America, Genpect, etc., I have completed B.com . Pls help me...

1150


printf("%d",printf("%d",printf("%d",printf("%s","ILOVECPROGRAM")))); whats the output

1400


What were the occupations of the people who lived within the Mauryan Empire?

587


aptitude

705


A frog wants to climb a pole which is 15 feet in height, frog can jump 3 feet every minute after which he rests for a minute where he slips down 2 feet. How much time will the frog take to reach the top of the pole?

607


If anybody knows the recruitment procedure of IOTL & POWER MECHANICAL. send me the placement papers if u hav... very urgent ...

3900


what is bidirectional?

1394


Danlaw placement questions and answers

1358


your project to describe and tell about : 1. My favorite things 2. My favorite places at home 3. Animals *Choose one of them to describe *Write on your paper *If you done, Send me *Did you get it

788


my question is : reverse a string in COBOL program (please write a code asap) input file: 1234abcdef abc*$#1___ cdef____ghi a_z_k_h___ 4_3_2_1___ ______5678 output file: 8765_____ 1_2_3_4__ h_k_z_a__ ihg____ghi 1#$*cba__ fedcb4321

1200