Tcs Programs NQT 2019
Tcs Programs NQT 2019
Tcs Programs NQT 2019
1. Factorial
#include<stdio.h>
void main()
{
int num,i,fa=1;
printf(“Enter a Number:- ”);
scanf(“%d”,&num);
for(i=1;i<=num;i++)
{
fa=fa*I;
}
printf(“Factorail = %d”,fa)
}
2. ODD-EVEN
#include<stdio.h>
void main()
{
int num;
printf(“Enter a Number:- ”);
scanf(“%d”,&num);
if(num%2==0)
printf(“%d is an even number”,num);
else
printf(“%d is an odd number”,num);
}
3. Area of Circle
#include<stdio.h>
void main()
{
int r;
float ar;
printf(“Enter the value of radius:- ”);
scanf(“%d”,&r);
ar=(float)3.14*r*r;
printf(“Area = %f”,ar);
}
4. Leap Year
#include<stdio.h>
void main()
{
int year;
printf(“Enter an Year :- ”);
scanf(“%d”,&year);
if(year%4==0)
printf(“%d is a Laep Year”,year);
else
printf(“%d is not a Leap Year”,year);
}
6. Area of Triangle
#include<stdio.h>
void main()
{
int b,h;
float ar;
printf(“Enter the value of base:- ”);
scanf(“%d”,&b);
printf(“Enter the value of height:- ”);
scanf(“%d”,&h);
ar=(float)(1/2)*b*h;
printf(“Area of Triangle = %f”,ar);
}
7. Reverse a Number
#include<stdio.h>
void main()
{
int n,rev;
printf(“Enter a Number:- ”);
scanf(“%d”,&n);
while(n!=0)
{
rev=rev*10;
rev=rev+n%10;
n=n/10;
}
printf(“Reverse Number = %d”,rev);
}
8. Pallindrome Number
#include<stdio.h>
void main()
{
int n,rev,temp;
printf(“Enter a Number:- ”);
scanf(“%d”,&n);
temp=n;
while(temp!=0)
{
rev=rev*10;
rev=rev+temp%10;
temp=temp/10;
}
If(n==rev)
printf(“%d is pallindrome”,n);
else
printf(“%d is not pallindrome”,n);
}
9. HCF & LCM
#include<stdio.h>
void main()
{
int a,b,x,y,t,hcf,lcm;
printf(“Enter two integars:- ”);
scanf(“%d %d”,&a,&b);
a=x;
b=y;
while(b!=0)
{
t=b;
b=a%b;
a=t;
}
hcf=a;
lcm=(x*y)/hcf;
printf(“hcf of %d and %d is %d”,x,y,hcf);
printf(“lcm of %d and %d is %d”,x,y,lcm);
void main()
int i,n,a=0,b=1,next;
scanf("%d",&n);
for(i=0;i<=n;++i)
printf("%d ",a);
next=a+b;
a=b;
b=next;
}
13. Swap Numbers
#include<stdio.h>
void main()
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
a=b; // b=a-b;
b=c; // a=a-b;
printf("a = %d b = %d ",a,b);
int main()
{
int i,flag=0,length;
char string[20];
length= strlen(string);
for(i=0;i<length;i++)
{
if(string[i]!=string[length-i-1])
{
flag=1;
break;
}
}
if(flag)
printf("%s is not pallindrome",string);
else
printf("%s is pallindrome",string);
}
15. Reverse String
#include<stdio.h>
#include<string.h>
int main() {
int i, j = 0;
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
return (0);