[go: up one dir, main page]

0% found this document useful (0 votes)
11 views59 pages

Programs

Uploaded by

allammd6786
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)
11 views59 pages

Programs

Uploaded by

allammd6786
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/ 59

Programs

1.c Write a c program to print your name on the screen


Program:
main()
{
printf(“MY NAME IS SHINY”);
}
OUTPUT:

2.c write a c program to print your name with stars on


the screen
Program:
main()
{
printf(“***************\n”);
printf(“******shiny*****\n”);
printf(“***************\n”);
}
Output:
3.c Write a c program to print you details on the
screen
Program
Main()
{
Printf(“Name: k.shiny\n”);
Printf(“Mother’s Name:k.visala\n”);
Printf(“Father’s Name: k.suresh\n”);
Printf(“Mobile NUMBER:xxxxxxxxxx\n”);
Printf(“EMAIL ID: xxxxxxxxxxx@gmail.com\n”);
}
//Note: (\n)—goes to the next line//
Output:

4.c write a c program to add 2 numbers and print it on


the screen
Program:
main()
{
int num1,num2,result;
num1=10;
num2=20;
result=num1+num2;
printf(“\n The sum of %d and % d is%d”,num1,num2,result);
}
Output:

5.c write a c program to subtract 2 numbers and print it


on the screen
Program:
main()
{
int num1,num2,result;
num1=10;
num2=20;
result=num1-num2;
printf(“\n The subtraction of %d and % d is %d” , num1, num2,
result);
}
Output:
6.c write a c program to multiply 2 numbers and print it
on the screen
Program:
main()
{
int num1,num2,result;
num1=10;
num2=20;
result=num1*num2;
printf(“\n The multiplication of %d and % d is %d” , num1,
num2,result);
}
Output:

7.c write a c program to divide 2 numbers and print it


on the screen (coeff..)
Program:
main()
{
int num1,num2,result;
num1=20;
num2=10;
result=num1/num2;
printf(“\n The division of %d and % d is %d” , num1,
num2,result);
}
Output:

8.c write a c program to divide 2 numbers and print it


on the screen (remainder..)
Program:
main()
{
int num1,num2,result;
num1=21;
num2=10;
result=num1%num2;
printf(“\n The division of %d and % d is %d” , num1,
num2,result);
}
Output:
9.C write a c program to add 2 numbers by taking input
from user
Program:
main()
{
int num1,num2,result;
printf(“enter 2 integer values\n”);
scanf(“%d %d ”,&num1,&num2);
result=num1+num2;
printf(“the sum of %d and %d is %d”,num1,num2,result);
}
Output:

10.C write a c program to subtract 2 numbers by taking


input from user
Program:
main()
{
int num1,num2,result;
printf(“enter 2 integer values\n”);
scanf(“%d %d ”,&num1,&num2);
result=num1-num2;
printf(“the difference of %d and %d is %d”,num1,num2,result);
}
Output:

11.C write a c program to multiply 2 numbers by taking


input from user
Program:
main()
{
int num1,num2,result;
printf(“enter 2 integer values\n”);
scanf(“%d %d ”,&num1,&num2);
result=num1*num2;
printf(“the product of %d and %d is %d”,num1,num2,result);
}
Output:

12.C write a c program to divide 2 numbers by taking


input from user(coeff..)
Program:
main()
{
int num1,num2,result;
printf(“enter 2 integer values\n”);
scanf(“%d %d ”,&num1,&num2);
result=num1/num2;
printf(“the coefficient of %d and %d is %d”,num1,num2,result);
}
Output:

13.C write a c program to divide 2 numbers by taking


input from user(remain..)
Program:
main()
{
int num1,num2,result;
printf(“enter 2 integer values\n”);
scanf(“%d %d ”,&num1,&num2);
result=num1%num2;
printf(“the modulus of %d and %d is %d”,num1,num2,result);
}
Output:
14.c write a program to calculate simple interest of the
loan taken by Mr.
Suresh and display the same as output
main()
{
float p,r,si;
int t;
printf(“\n Enter principle amount ”);
scanf(“%f”,&p);
printf(“\n Enter rate of interest ”);
scanf(“%f”,&r);
printf(“\n Enter tenure in years”);
scanf(“%d”,&t);
si=(p*t*r)/100;
printf(“\nThe simple interest to be paid by Mr.Suresh is %f ”,si);
}
Output:
15.c Mr. Ramesh basic salary is input through keyboard
who's dearness allowances is 40% of basic
salary,House rental allowance is 20% of the basic
salary.P.F. is 5% of the basic salary,bus allowance is
2000 rupees, write a c program to calculate net and
gross salaries of ramesh and display same
main()
{
float bs,hra,da,pf,net,gross;
int bus=2000;
printf(“\n Enter the basic salary of Mr. Ramesh”);
scanf(“%f”,&bs);
da=(bs*40)/100;
hra=(bs*20)/100;
pf=(bs*5)/100;
net=bs+da+hra;
gross=net-pf-bus;
printf(“\n Basic salary :%f”,bs);
printf(“\n Dearness Allowance:%f”,da);
printf(“\n House rental allowance :%f”,hra);
printf(“\n profund :%f”,pf);
printf(“\n Bus Allowance :%d”,bus);
printf(“\n Net salary :%f”,net);
printf(“\n Gross salary :%f”,gross);
}
Output:

16.c write a c program to calculate Area and perimeter


of rectangle when length and breadth were given as
input
main()
{
float l,b,area,peri;
printf("Enter length and breadth of the rectangle \n");
scanf("%f %f",&l,&b);
area=l*b;
peri=2*(l+b);
printf("The area of the rectangle is %f \n",area);
printf("The perimeter of the rectangle is %f \n",peri);
}
Output:
17.c write a c program to calculate area and
circumference of a circle where radius of circle is given
as input
#define pi 3.14
main()
{
float r,area,circum;
printf("Enter the radius of circle \n");
scanf("%f",&r);
area=pi*r*r;
circum=2*pi*r;
printf("The circumference of the circle is %f \n",circum);
printf("The area of the circle is %f \n",area);
}
Output:

18.c write a c program to convert fahreinheit


temperature to celsius when the temperature is given
through keyboard
main()
{
float f,c;
printf("Enter Fahreinheit \n");
scanf("%f",&f);
c=((f*5)/9)+32;
printf("celsius:%f \n",c);
}
Output:
Output:

19.c If the marks in 6 subjects of a student are input


through keyboard. Write a c program to calculate total
and average marks of student
main()
{
int a,b,c,d,e,f,total;
float average;
printf("Enter marks for 6 subjects \n");
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
total=a+b+c+d+e+f;
average=(a+b+c+d+e+f)/6;
printf("the total marks scored by the student is %d \n",total);
printf("the average marks scored by the student is %f \n",average);
}
Output:
20.c Write a c program to calculate sum and average of
3 numbers
main()
{
int a,b,c,sum,average;
printf(“Enter 3 integer values\n”);
scanf(“%d %d %d ”,&a,&b,&c);
sum=a+b+c;
average=a+b+c/3;
printf(“The sum of %d ,%d and %d is %d”,a,b,c,sum);
printf(“the average of %d, %d and %d is %d”,a,b,c,average);
}
Output:

21.c write a c program to convert fahreinheit


temperature to celsius and vice-versa
main()
{
float f,c,fh;
printf("Enter Fahreinheit \n");
scanf("%f",&f);
c=((f*5)/9)+32;
printf("celsius:%f \n",c);
fh=(c-32)*9/5;
printf("fahreinheit:%f",fh);
}
Output:

22.c write a c program to calculate simple interest


main()
{
float p,r,si;
int t;
printf("Enter principle amount \n");
scanf("%f",&p);
printf("Enter rate of interest \n");
scanf("%f",&r);
printf("Enter tenure in years \n");
scanf("%d",&t);
si=(p*t*r)/100;
printf("The simple interest to be paid is %f \n",si);
}
Output:

23.c write a c program to calculate compound interest


main()
{
float p,r,amount,ci;
int t;
printf("Enter principle amount \n");
scanf("%f",&p);
printf("Enter rate of interest \n");
scanf("%f",&r);
printf("Enter tenure in years \n");
scanf("%d",&t);
ci = p * (pow(1+r/100, t) );
printf("The compound interest to be paid is %.3f \n",ci);
}
Output:
24.c write a c program to find square root of a given
number
main()
{
int a,res;
printf("Enter value for a \n");
scanf("%d",&a);
res= sqrt(a);
printf("The square root of %d is %d \n ",a,res);
}
Output:

25.c Write a c program to print all bitwise operators in c


main()
{
int a,b;
printf("enter values for a and b \n");
scanf("%d %d",&a,&b);
printf(" Bitwise AND=%d \n",a&b);
printf(" Bitwise OR=%d \n",a|b);
printf(" Bitwise NOT=%d \n" ,~a);
}
Output:

26.c write a c program to calculate area of triangle


using heron's formula
#include <math.h>
main()
{
int a,b,c;
float s,area;
printf("Enter 3 values \n");
scanf("%d %d %d",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("the area of a triangle is %f \n",area);
}
Output:
27.c write a c program to calculate distance travelled
by an object
main()
{
int t;
float a,v,u,s;
printf("Enter value for initial velocity \n");
scanf("%f",&u);
printf("Enter value for final velocity \n");
scanf("%f",&v);
printf("Enter value for time taken \n");
scanf("%d",&t);
a=(v-u)/t;
s=(u*t)+(1/2)*(a*t*t);
printf("The Distance travelled by the object is %f",s);
}
Output:

28.C write a c program to evaluate following


expressions EXP1=A+B*C+(D*E)+F*G , EXP2=A/B*C-
B+A*D/3 , EXP3=A+++B---A , EXP4=(i++)+(++i)
main()
{

int A,B,C,D,E,F,G,i;
float res1,res2,res3,res4;
printf("Enter values for A,B,C,D,E,F,G,i \n");
scanf("%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G,&i);
res1=A+B*C+(D*E)+F*G;
res2=A/B*C-B+A*D/3;
res3=A+++B---A;
res4=(i++)+(++i);
printf("The value for EXP1 is %f \n",res1);
printf("The value for EXP2 is %f \n",res2);
printf("The value for EXP3 is %f \n",res3);
printf("The value for EXP4 is %f \n",res4);
} Output:

29.C write a c program to find maximum of 3 numbers


using conditional operation
main()
{
int a,b,c,max;
printf("Enter values for a, b and c");
scanf("%d %d %d",&a,&b,&c);
max=((a>b)&&(a>c))?a:((b>a)&&(b>c))?b:c;
printf("The largest number is %d",max);
}
Output:

30.C write a c program to take marks of 5 subjects as


input through keyboard[int] . find the total , average in
float
main()
{
int sub1,sub2,sub3,sub4,sub5;
float total,avg;
printf("Enter marks scored by the student in each subject \n");
scanf("%d %d %d %d %d",&sub1,&sub2,&sub3,&sub4,&sub5);
total=(sub1+sub2+sub3+sub4+sub5);
avg=(sub1+sub2+sub3+sub4+sub5)/5;
printf("The total marks scored by the student is %.2f \n",total);
printf("The avg marks secured by the student is %.2f \n",avg);
}
Output:

31.C If a 5 digit number is input through keyboard,


write a c program to reverse the numbers
main()
{
// d1,d2,d3,d4,d5 are the 5digits to be taken
// n is the 5 digit number
// rev=reversed
int n,rev,rem;
printf("Enter a 5 digit number \n");
scanf("%d",&n);
rev=0;
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
printf("the reversed number is %d",rev);
}
Output:

32.C Consider a currency system in which there are


notes OF 6 denominations namely Rs. 1, Rs. 2, Rs. 5,
Rs. 10, Rs. 50, Rs. 100. if the sum of Rs. N is entered
through keyboard, write a c program to compute the
smallest number of notes that will combine to give Rs.
N
main()
{
int N, notes_100, notes_50, notes_10, notes_5, notes_2, notes_1;
printf("Enter the total amount (Rs. N): ");
scanf("%d", &N);
notes_100 = N / 100;
N = N % 100;
notes_50 = N / 50;
N = N % 50;
notes_10 = N / 10;
N = N % 10;
notes_5 = N / 5;
N = N % 5;
notes_2 = N / 2;
N = N % 2;
notes_1 = N;
printf("Smallest number of notes:\n");
printf("Rs. 100: %d\n", notes_100);
printf("Rs. 50: %d\n", notes_50);
printf("Rs. 10: %d\n", notes_10);
printf("Rs. 5: %d\n", notes_5);
printf("Rs. 2: %d\n", notes_2);
printf("Re. 1: %d\n", notes_1);
}
OUTPUT:
33.CIf the 5 digit number is input through keyboard
write a c program to calculate the sum of its digits
Program:
main()
{
int number, sum = 0, digit;
printf("Enter a five-digit number: ");
scanf("%d", &number);
while (number > 0)
{
digit = number % 10;
sum += digit;
number /= 10;
printf("The sum of the digits is: %d\n", sum);
}
}
Output:

34.c Write a program to receive Cartesian co-ordinates


(x, y) of a point and convert them into polar co-
ordinates (r, o).
Hint: r = sqrt(x²+y²) and tan (y/x)
Program:
main()
{
double x, y, r, theta;
printf("Enter the Cartesian coordinates (x, y): ");
scanf("%lf %lf", &x, &y);
r = sqrt(x * x + y * y);
theta = atan2(y, x);
theta = theta * (180.0 / M_PI);
printf("Polar coordinates: r = %.2lf, θ = %.2lf
degrees\n", r, theta);
}
Output:

35.c If value of an angle is input through the keyboard, write a


program to print all its Trigonometric ratios
Program
#define DEG_TO_RAD(angle) ((angle) * (M_PI / 180.0))
main()
{
double angle, sin_val, cos_val, tan_val, sec_val, csc_val, cot_val;
printf("Enter the angle in degrees: ");
scanf("%lf", &angle);
double radian = DEG_TO_RAD(angle);
sin_val = sin(radian);
cos_val = cos(radian);
tan_val = tan(radian);
if (cos_val != 0)
{
sec_val = 1 / cos_val;
}
else
{
sec_val = INFINITY;
}
if (sin_val != 0)
{
csc_val = 1 / sin_val;
cot_val = 1 / tan_val;
}
else
{
csc_val = INFINITY;
cot_val = INFINITY;
}
printf("Trigonometric Ratios for %.2lf degrees:\n", angle);
printf("sin(%.2lf) = %.4lf\n", angle, sin_val);
printf("cos(%.2lf) = %.4lf\n", angle, cos_val);
printf("tan(%.2lf) = %.4lf\n", angle, tan_val);
printf("sec(%.2lf) = %.4lf\n", angle, sec_val);
printf("csc(%.2lf) = %.4lf\n", angle, csc_val);
printf("cot(%.2lf) = %.4lf\n", angle, cot_val);
}
OUTPUT:
36.c Two numbers are input through the keyboard into two locations
C and D. Write a program to interchange the contents of C and D
Program:
main()
{
int C, D, temp;
printf("Enter the value of C: ");
scanf("%d", &C);
printf("Enter the value of D: ");
scanf("%d", &D);
printf("\nBefore swapping: C = %d, D = %d\n", C, D);
temp = C;
C = D;
D = temp;
printf("After swapping: C = %d, D = %d\n", C, D);
}
Output:
38.c Write a program to receive values of latitude (L1, L2) and
longitude (G1, G2), in degrees, of two places on the earth and output
the distance (D) between them in nautical miles. The formula for
distance in nautical miles is:
D=3963 cos (sin L1 sin L2 + cos 11 cos L2 cos (G2-G1))
Program:
main()
{
double L1, L2, G1, G2, D;
printf("Enter latitude of first place (L1 in degrees): ");
scanf("%lf", &L1);
printf("Enter longitude of first place (G1 in degrees): ");
scanf("%lf", &G1);
printf("Enter latitude of second place (L2 in degrees): ");
scanf("%lf", &L2);
printf("Enter longitude of second place (G2 in degrees): ");
scanf("%lf", &G2);
L1 = DEG_TO_RAD(L1);
L2 = DEG_TO_RAD(L2);
G1 = DEG_TO_RAD(G1);
G2 = DEG_TO_RAD(G2);
D = 3963 * acos(sin(L1) * sin(L2) + cos(L1) * cos(L2) * cos(G2 - G1));
printf("The distance between the two places is: %.2lf nautical
miles\n", D);
}
Output:

39.c Wind-chill factor is the felt air temperature on exposed skin due
to wind. The wind-chill temperature is always lower than the air
temperature, and is calculated as per the following formula:
wcf=35.74+0.6215t+ (0.42751-35.75)*016. where t is temperature
and v is wind velocity. Write a program to receive values of t and v
and calculate wind-chill factor (wcf).
Program:
main()
{
double t, v, wcf;
printf("Enter the temperature (in Fahrenheit): ");
scanf("%lf", &t);
printf("Enter the wind velocity (in miles per hour): ");
scanf("%lf", &v);
wcf = 35.74 + 0.6215 * t + (0.4275 * t - 35.75) * pow(v, 0.16);
printf("The Wind-Chill Factor (WCF) is: %.2lf\n", wcf);
}
Output:

Unit -2
CONTROL STATEMENTS:
40.C write a c program to read a number from user and
print "It is negative" , if it is negative (simple if)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n<0)
{
printf("It is negative \n");
}
printf("Done");
}

Output:
41.C write a c program to read a number from the user
and print "It is even", if it is even (simple if)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n%2==0)
{
printf("It is even \n");
}
printf("Done");
}
Output:
42.C write a c program to a read a character from the
user and print "It is a vowel", if it is a vowel(simple if)
main()
{
char ch;
printf("Enter a character \n");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
printf("It is vowel \n");
}
}
Output:

43.C write a c program to read a number and check


whether it is even or odd(if else)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n%2==0)
{
printf("It is even \n");
}
else
{
printf("It is odd \n");
}
printf("Done");
}
Output:

44.C write a c program to read a number and check


whether it is divisible by 13 or not(if else)
main()
{
int n;
printf("Enter a number \n");
scanf("%d",&n);
if(n%13==0)
{
printf("It is divisible \n");
}
else
{
printf("It is not divisible \n");
}
printf("Done");
}
Output:

45.C write a c program to read the character from the


user and check whether it is a vowel or consonant(if
else)
main()
{
char ch;
printf("Enter a character \n");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
printf("It is vowel \n");
}
else
{
printf("It is consonant \n");
}
printf("Done");
}

Output:

46.C If ages of Ram , Shyam and Ajay are input through


keyboard . Write a c program to determine the
youngest of the three (if else if ladder)
main()
{
float r,s,a;
printf("Enter age of Mr. Ram \n");
scanf("%f",&r);
printf("Enter age of Mr. Shyam \n");
scanf("%f",&s);
printf("Enter age of Mr. Ajay \n");
scanf("%f",&a);
if(r<s&&r<a)
{
printf("Ram is youngest \n");
}
else if(s<r&&s<a)
{
printf("Shyam is the youngest \n");
}
else
{
printf("Ajay is the youngest \n");
}
}
Output:

47.C write a c program to calculate sum and average


of 6 subjects and print A grade if the average marks are
75 and above , B grade if the avg marks are 65-75, C
grade if the avg marks are 55-65,D grade if the avg
marks are 45-55, and fail if the avg marks are 45 below
main()
{
int sub1,sub2,sub3,sub4,sub5,sub6;
float total,avg;
printf("Enter marks scored by the student in each subject \n");
scanf("%d %d %d %d %d %d",&sub1, &sub2,& sub3,& sub4,&
sub5,&sub6);
total=(sub1+sub2+sub3+sub4+sub5+sub6);
avg=(sub1+sub2+sub3+sub4+sub5+sub6)/6;
printf("The total marks scored by the student is %.2f \n",total);
printf("The avg marks secured by the student is %.2f \n",avg);
if(avg>75&&avg<=100)
{
printf("The grade is A \n");
}
else if(avg>65&&avg<=75)
{
printf("The grade is B \n");
}
else if(avg>55&&avg<=65)
{
printf("The grade is C \n");
}
else if(avg>45&&avg<=55)
{
printf("The grade is D\n");
}
else if(avg>0&&avg<=45)
{
printf("FAIL \n");
}
else
{
printf("Wrong Input");
}
}
Output:

48.C
write a c pragram to read the float values and perform
an arithmetic operation chosen by the user (switch
case)
main()
{
char operator;
int n1,n2,res;
printf("Enter an operator\n ");
scanf("%c",&operator);
printf("Enter 2 numbers \n");
scanf("%d %d",&n1,&n2);
switch(operator)
{
case'+':
res=n1+n2;
printf("%d+%d=%d \n",n1,n2,res);
case'-':
res=n1-n2;
printf("%d-%d=%d \n",n1,n2,res);
case'*':
res=n1*n2;
printf("%d*%d=%d \n",n1,n2,res);
case'/':
res=n1/n2;
printf("%d/%d=%d \n ",n1,n2,res);
default:
printf("wrong input \n");
}
}OUTPUT:

50.c write a c program to print 1st 'n' natural numbers


(FOR)
PROGRAM:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
printf("the first %d natural numbers \n ",n);
for(i=1;i<=n;i++)
{
printf("%d",i);
}
}
OUTPUT:

write a c program to print 1st 'n' natural numbers


(WHILE)
PROGRAM:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
printf("the first %d natural numbers \n ",n);
i=1;
while(i<=n)
{
printf("%d",i);
i++;
}
}
OUTPUT:

write a c program to print 1st 'n' natural numbers (do


WHILE)
PROGRAM:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
printf("the first %d natural numbers \n ",n);
i=1;
do
{
printf("%d",i);
i++;
}while(i<=n);
}
OUTPUT:

51.c write a c program to print "n" whole numbers


Program:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
printf("the first %d whole numbers \n ",n);
for(i=0;i<=n;i++)
{
printf("%d",i);
}
}
OUTPUT:
52.c write a c program to print "n" even numbers
Program:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==0)
{
printf("%d",i);
}
}
}
OUTPUT:

53.c write a c program to print "n" odd numbers


Program:
main()
{
int n,i;
printf("Enter value \n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
printf("%d",i);
}
}
}
OUTPUT:

54.cWrite a c program to print mathematical table


where the table to be printed , till where we need to
print the mathematical table are inputs through
keyboard
Program:
main()
{
int n,m,i;
printf("Enter a number for table ");
scanf("%d",&n);
printf("Enter a value till where we need table to be printed \n");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
printf("%d x %d= %d \n",n,i,(n*i));
}
}
OUTPUT:

55.c write a c program to check whether a given


number is a pallendrome
Program:
main()
{
int n,original,rem,rev=0;
printf("Enter n value \n");
scanf("%d",&n);
original=n;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
if(rev==original)
{
printf("The number is a palindrome");
}
else
{
printf("the number is not a palindrome");
}
}
OUTPUT:

56.cwrite a c program to check whether a given


number is a armstrong or not
Program:
main()
{
int n,original,res=0,rem;
printf("Enter n value \n");
scanf("%d",&n);
original=n;
while(n>0)
{
rem=n%10;
res=res+(rem*rem*rem);
n=n/10;
}
if(res==original)
{
printf("Armstrong number");
}
else
{
printf("Not an Armstrong number");
}
}
OUTPUT:

57.cwrite a c program to check the given number is a


prime number or not
Program:
main()
{
int i,n,count=0;
printf("Enter n value");
scanf("%d",&n);
for(i=2;i<=(n-1);i++)
{
if(n%i==0)
{
count++;
}
}
if(count==0)
{
printf("\n It is prime number");
}
else
{
printf("\n It is not a prime number");
}
}
OUTPUT:
58.c write a c program to print all the prime numbers
before the given number
Program:
main()
{
int n,count=0,i,m;
printf("Enter m value \n");
scanf("%d",&m);
for(n=1;n<=m;n++)
{
for(i=2;i<=(n-1);i++)
{
if(n%i==0)
{
count++;
}
}
if(count==0)
{
printf("%d",n);
}
}
}
OUTPUT:
59.c Write a C program to find the biggest among
three numbers using nested-if statement.
Program:
main()
{
int a, b, c;
printf("Enter a,b,c values:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("%d is the big\n",a);
}
else
{
printf("%d is the big\n",c);
}
}
else
{
if(b>c)
{
printf("%d is the big\n",b);
}
else
{
printf("%d is the big\n",c);
}
}
}
OUTPUT:

60.c write a c program to find the roots of the quadratic


equation
Program:

62.c write a c program to find the given year is a leap


year or not
Program:

main()
{
int year;
printf("Enter any year:");
scanf("%d",&year);
if(year%4==0)
{
printf("%d is leap year\n", year);
}
else
{
printf("%d is non leap year\n", year);
}
}
OUTPUT:

63.c write a c program to find the factorial of given


number using any loop
Program:
main()
{
int n,i,fact=1;
printf(" Enter a number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf(" \n The factorial is %d ",fact);
}
OUTPUT:

64.c Write a program using do-while loop to read the


numbers until -1 and also count the positive, negative
and zeros encountered by the users.
Program:
main()
{
int n,neg=0,pos=0,zero=0;
do
{
printf("Enter a number \n");
scanf("%d",&n);
if(n<0)
{
neg++;
}
else if(n>0)
{
pos++;
}
else if(n==0)
{
zero++;
}
}while(n!=-1);
printf("positive numbers %d \n",pos);
printf("negative numbers %d \n",neg);
printf("zero numbers %d \n",zero);

}
65.c write a c program to construct a pyramid of
numbers
Program:
main()
{
int n,j,i;
printf("Enter the value for n:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",j);
}
printf( "\n");
}
OUTPUT:

66.c write a c program to construct a pyramid of


numbers\
Program:
main()
{
int n,j,i;
printf("Enter the value for n:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
printf("%d",j);
}
printf( "\n");
}
OUTPUT:

67.cwrite a c program to construct a pyramid of stars


Program:
main()
{
int n, i, j;
printf("Enter number of rows:" );
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}

}
OUTPUT:

You might also like