0% found this document useful (0 votes)
36 views

Tcs Programs NQT 2019

The document contains 15 C programming code examples that demonstrate common programming concepts and problems including: 1) Factorial calculation 2) Determining if a number is even or odd 3) Calculating the area of a circle 4) Determining if a year is a leap year 5) Summing the digits of a number

Uploaded by

Rishi Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Tcs Programs NQT 2019

The document contains 15 C programming code examples that demonstrate common programming concepts and problems including: 1) Factorial calculation 2) Determining if a number is even or odd 3) Calculating the area of a circle 4) Determining if a year is a leap year 5) Summing the digits of a number

Uploaded by

Rishi Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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);
}

5. Sum of Digits of Numbers


#include<stdio.h>
void main()
{
int n,sum=0,rem;
printf(“Enter a number:- ”);
scanf(“%d”,&n);
while(n!=0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf(“SUM of Digits = %d”,sum);
}

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);

10. Armstrong Number


#include<stdio.h>
void main()
{
int n,sum=0,y,rem;
printf("Enter a number:- ");
scanf("%d",&n);
t=n;
while(t!=0)
{
rem=t%10;
sum=sum+rem*rem*rem;
t=t/10;
}
if(n==sum)
printf("No is Armstrong");
else
printf("No is not Armstrong");
}
11. Prime Number
#include<stdio.h>
void main()
{
int num,i,p=0;
printf("enter a number: ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
if(num%i==0)
{
p++;
}
}
if(p==2)
printf("%d is a prime numbner",num);
else
printf("%d is not a prime number",num);
}

12. Febbonacci Series


#include<stdio.h>

void main()

int i,n,a=0,b=1,next;

printf("Enter the no of terms: ");

scanf("%d",&n);

printf("Febbonacci Series : ");

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;

printf("Enter value of a: ");

scanf("%d",&a);

printf("Enter value of b: ");

scanf("%d",&b);

c=a; // a=a+b; Without using third variable

a=b; // b=a-b;

b=c; // a=a-b;

printf("a = %d b = %d ",a,b);

14. Pallindrome String


#include <stdio.h>

int main()
{
int i,flag=0,length;
char string[20];

printf("Enter a String: ");


scanf("%s", &string);

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() {

char str[100], temp;

int i, j = 0;

printf("\nEnter the string :");

gets(str);

i = 0;

j = strlen(str) - 1;

while (i < j) {

temp = str[i];

str[i] = str[j];

str[j] = temp;

i++;

j--;

printf("\nReverse string is :%s", str);

return (0);

You might also like