0% found this document useful (0 votes)
29 views31 pages

LB PS Unit 2 and 3

The document contains a series of C programming exercises, each with a specific task and corresponding code. The tasks range from simple output statements to more complex calculations, such as finding areas, averages, and conversions. Each exercise includes the necessary code snippets to accomplish the task, demonstrating fundamental programming concepts in C.

Uploaded by

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

LB PS Unit 2 and 3

The document contains a series of C programming exercises, each with a specific task and corresponding code. The tasks range from simple output statements to more complex calculations, such as finding areas, averages, and conversions. Each exercise includes the necessary code snippets to accomplish the task, demonstrating fundamental programming concepts in C.

Uploaded by

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

LBPS Unit 2 and 3 question:-

1. Write a c program to print hello word.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hello,world");
getch();
}
2. Write a c program to print your name and college details in individual
line.
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("name:maya chaudhary\n”);
printf("college:indus university \n");
getch();
}

3. Write a c program to print the following details with the use of printf().
1
23
456
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("1\n");
printf("2 3\n");
printf("4 5 6\n");
printf("7 8 9 10\n");
getch();
}
*
**
***
****
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*\n");
printf("* *\n");
printf("* * *\n");
printf("* * * *\n");
getch();
}
&
&&
&&&
&&&&
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("&\n");
printf("& &\n");
printf("& & &\n");
printf("& & & &\n");
getch();
}
4. Write a c program to print the multiplication table of given number from
the user.
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B;
clrscr();
printf("enter the value A= ");
scanf("%d",&A);
printf("%d*1=%d\n",A,A*1);
printf("%d*2=%d\n",A,A*2);
printf("%d*3=%d\n",A,A*3);
printf("%d*4=%d\n",A,A*4);
printf("%d*5=%d\n",A,A*5);
printf("%d*6=%d\n",A,A*6);
printf("%d*7=%d\n",A,A*7);
printf("%d*8=%d\n",A,A*8);
printf("%d*9=%d\n",A,A*9);
printf("%d*10=%d\n",A,A*10);
getch();
}

5. Write a c program to find the sum of 2 numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
c=a+b;
printf("sum=%d",c);
getch();
}

6. Write a c program to calculate average of 3 numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
float d;
clrscr();
printf("enter the value of a,b and c");
scanf("%d%d%d",&a,&b,&c);
d=(a+b+c)/3;
printf("average=%f",d);
getch();
}

7. Write a c program to find the area of circle. Area=pi*r*r (use PI as


Constant.
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float ar;
clrscr();
printf("enter the r");
scanf("%d",&r);
ar=3.14*r*r;
printf("%f",ar);
getch();
}
8. Write a c program to find the simple interest. SI=(P*R*N)/100
#include<stdio.h>
#include<conio.h>
void main()
{
int P,R,N;
float SI;
clrscr();
printf("enter the value of P,R and N");
scanf("%d%d%d",&P,&R,&N);
SI=(P*R*N)/100;
printf("%f",SI);
getch();
}
9. Write a c program to convert Fahrenheit temperature into Celsius
temperature. C=((F-32)*5)/9
#include<stdio.h>
#include<conio.h>
void main()
{
int F;
float C;
clrscr();
printf("enter F");
scanf("%d",&F);
C=((F-32)*5)/9;
printf("%f",C);
getch();
}
10. Write a c program to find the area of squre. Area=L*L.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,l;
clrscr();
printf("enter the value of l");
scanf("%d",&l);
a=l*l;
printf("%d",a);
getch();
}
11. Write a c program to find the area of rectangle. Area=L*B.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,l;
clrscr();
printf("enter the value of l and b");
scanf("%d%d",&l,&b);
a=l*b;
printf("%d",a);
getch();
}
12. Write a c program to inter change the value of 2 variable with another
variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,tem;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
tem=a;
a=b;
b=tem;
printf("%d%d",a,b);
getch();
}
13. Write a c program to inter change the value of 2 variable without another
variable.
a=a+b
b=a-b
a=a-b
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
getch();
}
14. Write a c program to find area of triangle when three sides are given.
(semi perimeter) S=(a+b+c)/2
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float s,a,b,c,area;
clrscr();
printf("enter the value of a,b and c");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area of tringle=%f",area);
getch();
}
15.Write a c program to convert minutes to hours and remaining minutes.
Hour=min/60
Remaining min=min%60
#include<stdio.h>
#include<conio.h>
void main()
{
int min,hour,rmin;
clrscr();
printf("enter the min:");
scanf("%d",&min);
hour=min/60;
rmin=min%60;
printf("%d minutes = %d hour %d minutes",min,hour,rmin);
getch();
}
16. Write a c program to convert meter into kilometer and remaining meter.
Km=meter/1000 (convert into integer form)
RM=meter%1000 .
#include<stdio.h>
#include<conio.h>
void main()
{
int m,km,rm;
clrscr();
printf("enter the value: ");
scanf("%d",&m);
km=m/1000;
rm=m%1000;
printf("%d = m\n" "%d=km\n" "%d=rm\n",m,km,rm);
getch();
}
17. Write a c program to take measurement in centimeters and convert it into
meters.
#include<stdio.h>
#include<conio.h>
void main()
{
int centim,m,cm;
clrscr();
printf("enter value in centim: ");
scanf("%d",&centim);
m=centim / 100;
cm=centim % 100;
printf("%d centim = %d m \n",centim,m);
printf("%d centim = %d cm \n",centim,cm);
getch();
}
18. Write a c program to find the given number is odd or even.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf("enter an integer: ");
scanf("%d",&a);
if(a%2==0)
{
printf("even number");
}
else
{
printf("odd number");
}
getch();
}
19. Write a c program to find maximum number between 2 numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter two number: ");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("%d",a);
}
else
{
printf("%d",b);
}
getch();
}

20. Write a c program to check whether the triangle is valid or not?


Condition is= 3 sides of triangle will not be 0 and total of 3 sides will be
exactly 180.
(a and b and c not be 0 and a+b+c=180)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum;
clrscr();
printf("enter first angle of triangle: ");
scanf("%d",&a);
printf("enter second angle of triangle: ");
scanf("%d",&b);
printf("enter third angle of triangle: ");
scanf("%d",&c);
sum=a+b+c;
if(sum==180)
{
printf("triangle is valid");
}
else
{
printf("triangle is not valid");
}
getch();
}
21. Write a c program to enter distance in kilometer and convert it into meter,
feet, inches, centimeter.
Meter=(distance*1000)
Feet=(distance*3280.84)
Inches =(distance*39370.1)
Centimeter=(distance * 100000)
#include<stdio.h>
#include<conio.h>
void main()
{
float distance,m,feet,inches,cm;
clrscr();
printf("enter kilometers: ");
scanf("%f",&distance);
m=distance*1000;
feet=distance*3280.84;
inches=distance*39370.1;
cm=distance*100000;
printf("meter = %f\n",m);
printf("feet = %f\n",feet);
printf("inches = %f\n",inches);
printf("cm = %f\n",cm);
getch();
}

22. Write a c program to convert days into year, months and remaining days.
Year=days/365
Month=(days-year*365)/30
Remdays=(days –year *365 – month*30)
#include<stdio.h>
#include<conio.h>
void main()
{
int days,year,months,RD;
clrscr();
printf("enter days: ");
scanf("%d",&days);
year=days/365;
months=(days-year*365)/30;
RD=(days-year*365-months*30);
printf("%d days = %d year %d months and %d remining days",days,year,months,RD);
getch();
}
23. Write a c program to find the value of reminder and quotient,
Rem=dividend/divisor
Quo= dividend%divisor
#include<stdio.h>
#include<conio.h>
int main()
{
int dividend,divisor,rem,quo;
clrscr();
printf("enter dividend: ");
scanf("%d",&dividend);
printf("enter divisor: ");
scanf("%d",&divisor);
if(divisor == 0)
{
printf("error : divisor cannot be zero.\n");
}
rem=dividend / divisor;
quo=dividend % divisor;
printf("remainder: %d\n",rem);
printf("quotient: %d\n",quo);
getch();
}
24. Write a c program to check whether a temperature is below freezing point
or not. condition is= if temperature is <32 then it is below freezing point
otherwise it is above the freezing point.
#include <stdio.h>
#include <conio.h>
void main()
{
float temperature;
clrscr();
printf (“enter the temperature is Celsius: ”);
scanf(“%f”,&temperature);
temperature<0?printft(“the temperature is below freezing point \n”):printf(“the
temperature is above freezing point \n”);
getch();
}

25. Write a c program to find the student is pass or not. (use global variable)
calculate the total of 4 subject mark.
check condition : if total>60 then student will be pass otherwise fail.
#include<stdio.h>
#include <conio.h>
void main()
{
Int pass, fail, sub1, sub2, sub3, sub4, total;
clrscr();
printf(“enter marks for sub1:\n");
scanf(“%d”,&sub1);
printf(“enter marks for sub2:\n”);
scanf(“%d” ,&sub2);
printf(“enter marks for sub3:\n”);
scanf(“%d”,&sub3);
printf(“enter marks for sub4:\n");
scanf(“%d”,&sub4);
total-sub1+sub2+sub3+sub4;
(total>60)?printf(“student has passed\n”):printf(“student has failed\n”);
getch();
}

26. write a program to find the given no is positive or negative.


#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter the number: ");
scanf("%d",&n);
if(0<n)
printf("%d is positive number",n);
else if(0>n)
printf("%d is negative number",n);
else
printf("%d is zero number",n);
getch();
}
27. write a program to find largest no from 3 numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,num3;
clrscr();
printf("enter 3 numbers\n");
scanf("%d%d%d",&num1,&num2,&num3);
if(num1>num2 && num1>num3)
{
printf("%d is greater",num1);
}
else if(num2>num1 && num2>num3)
{
printf("%d is greater",num2);
}
else
{
printf("%d is greater",num3);
}
getch();
}
28. write a program to check whether a person is eligible to vote or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("enter age=");
scanf("%d",&age);
if(age<18)
{
printf("you are not eligible for vote");
}
else
{
printf("now you can eligible for vote");
}
getch();
}
29. write a c program to check the given no is divisible by both 5 and 8 or
only by 5 or only by 8.
#include <stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);

if (num % 5 == 0 && num % 8 == 0) {


printf("%d is divisible by both 5 and 8.\n", num);
} else if (num % 5 == 0) {
printf("%d is only divisible by 5.\n", num);
} else if (num % 8 == 0) {
printf("%d is only divisible by 8.\n", num);
} else {
printf("%d is not divisible by 5 or 8.\n", num);
}
getch();
}
30. write a c program to display whether information.
if whether >=50 “It is hot whether !
if whether <50 and >=35 It is a stormy whether
if whether <35 and >=25 It is a sticky whether
if whether <25 and >=15 It is a pleasant whether
else it is very cold whether
#include<stdio.h>
#include<conio.h>
void main()
{
int w;
clrscr();
printf("enter weather: ");
scanf("%d",&w);
if(w>=50)
{
printf("it is hot weather\n");
}
else if(w<50 && w>=35)
{
printf("it is stormy weather\n");
}
else if(w<35 && w>=25)
{
printf("it is sticky weather\n");
}
else if(w<25 && w>=15)
{
printf("it is pleasant weather\n");
}
else
{
printf("it is very cold weather\n");
}
getch();
}

31. write a menu driven program.


+ addition of 2 numbers.
- subtraction of numbers.
* multiplication of 2 numbers.
/ division of 2 numbers.
other then above sign display enter valid sign.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,num1,num2,result;
char sign;
clrscr();
while(1)
{
printf("\n\n\n***MENU***\n");
printf("1.addition of 2 numbers.\n");
printf("2.subtraction of 2 numbers.\n");
printf("3.multiplication of 2 numbers.\n");
printf("4.division of 2 numbers.\n");
printf("5.exit.\n");
printf("enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
result=num1+num2;
printf("sum of %d and %d is: %d\n",num1,num2,result);
break;
case 2:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
result=num1-num2;
printf("subtraction of %d and %d is:%d\n",num1,num2,result);
break;
case 3:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
result=num1*num2;
printf("multiplication of %d and %d is: %d\n",num1,num2,result);
break;
case 4:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
if(num2==0)
{
printf("division by zero is not allowed.\n");
}
else
{
result=num1/num2;
printf("division of %d and %d is: %d\n",num1,num2,result);
}
break;
case 5:
printf("exiting...\n");
("exit(0)");
default:
printf("invalid choice.please try again.\n");
}
}
getch();
}
32. write a menu driven program.
1. addition of 2 numbers.
2. swapping of 2 numbers.
3. no is even or not.
4. find maximum numbers between 2 numbers.
5. invalid choice.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice,num1,num2,swap,maximum,iseven;
float sum;
while(1)
{
printf("\n\n\n******MENU******\n");
printf("1.addition of 2 numbers.\n");
printf("2.swapping of 2 numbers.\n");
printf("3.check if a number is even or not.\n");
printf("4.find maximum numbers between 2 numbers.\n");
printf("5.exit.\n");
printf("enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
sum=(float)num1+num2;
printf("sum of %d and %d is:%.2f\n",num1,num2,sum);
break;
case 2:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",num2);
printf("values before swapping:num1 = %d,num2 = %d\n",num1,num2);
break;
case 3:
printf("enter a number: ");
scanf("%d",&num1);
iseven = num1 %2;
if(iseven==0)
{
printf("%d is even.\n",num1);
}
else
{
printf("%d is not even.\n",num1);
}
break;
case 4:
printf("enter first number: ");
scanf("%d",&num1);
printf("enter second number: ");
scanf("%d",&num2);
maximum = num1 > num2 ? num1 : num2;
printf("maximum number between %d and %d is: %d\n",num1,num2,maximum);
break;
case 5:
printf("exiting...\n");
("exit(0)");
("default");
printf("invalid choice.please try again.\n");
}
}
getch();
}
33. Write a C program to find whether a given year is a leap year or not.
if year % 400 == 0 or year % 4== 0 year is leap year
else if year % 100 == 0 then year is not leap year
else - year is not leap year
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("enter year: ");
scanf("%d",&year);
if(year%400==0 || year%4==0)
{
printf("it is a leap year");
}
else
{
printf("it is not a leap year");
}
getch();
}
34. Write a C program to read roll no, name and marks of three subjects and
calculate the total, percentage and division.
35. Write a c program to print 1 to 20 numbers with looping.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("numbers from 1 to 20\n");
for(i=1;i<=20;i++)
{
printf("%d\n",i);
}
printf("\n");
getch();
}
36. Write a c program to print 1 to n numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
clrscr();
printf("enter n: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d",i);
}
getch();
}
37.Write a c program to print the n to 1 numbers.
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i;
clrscr();
printf("Enter the number of terms: ");
scanf("%d", &n);
for (i = n; i >= 1; i--)
{
printf("%d ", i);
}
printf("\n");
getch();
}
38.Write a c program to print the multiplication table of given no.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
printf("%d*%d=%d\n",num,i,num*i);
}
printf("\n");
getch();
}
39.Write a c program to print the addition and multiplication of 1 to n
Numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
printf("\naddition:\n");
for(i=1;i<=num;i++)
{
printf("%d+%d=%d\n",i,num,i+num);
}
printf("\nmultiplication:\n");
for(i=1;i<=num;i++)
{s
printf("%d*%d=%d\n",i,num,i*num);
}
printf("\n");
getch();
}

40.Write a c program to find odd no between 1 to n numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
printf("\nodd numbers between 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2!=0)
{
printf("%d\n",i);
}
}
printf("\n");
getch();
}
41.Write a c program to find even no between 1 to n numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
printf("\neven numbers between 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2==0)
{
printf("%d\n",i);
}
}
printf("\n");
getch();
}
42.Write a c program to find odd and even no between n to 1 numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
printf("\neven numbers betweem 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2==0){
printf("%d\n",i);
}
}
printf("\nodd numbers between 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2!=0)
{
printf("%d\n",i);
}
}
printf("\n");
getch();
}
43.Write a program to print Fibonacci series up to n numbers.
0 1 1 2 3 5 8 ………
i = 0; j = 1; k = i + j;
while (k <= n)
{ printf (" %d", k);
i = j; j = k; k = i + j; }
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("enter the n");
scanf("%d",&n);
i=0;
j=1;
k=i+j;
while(k<=n)
{
printf("%d\n",k);
i=j;
j=k;
k=i+j;
}
getch();
}

44.Write a c program to find the factorial of a given no.


For example= given no is=6
So factorial is=6*5*4*3*2*1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,f=1,a;
clrscr();
printf("enter the numbers for finding factorial: ");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
f=f*i;
}
printf("factorails=%d",f);
getch();
}
45.Write a c program to find sum and average of n numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the number: ");
scanf("%d",&num);
printf("\neven numbers betweem 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2==0){
printf("%d\n",i);
}
}
printf("\nodd numbers between 1 and %d:\n",num);
for(i=1;i<=num;i++)
{
if(i%2!=0)
{
printf("%d\n",i);
}
}
printf("\n");
getch();
}
46.Write a c program to display the square and cube of the number 1 to up to
given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the upper limit of the number range: ");
scanf("%d",&num);
printf("\nnumber square cube\n");
for(i=1;i<=num;i++)
{
printf("%d %d %d\n",i,i*i,i*i*i);
}
printf("\n");
getch();
}
47.Write a c program to draw the given pattern.
*
**
***
****
*****
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*\n");
printf("* *\n");
printf("* * *\n");
printf("* * * *\n");
printf("* * * * *\n");
getch();
}
48.Write a c program to draw the given pattern.
*****
****
***
**
*
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("* * * * *\n");
printf("* * * *\n");
printf("* * *\n");
printf("* *\n");
printf("*\n");
getch();
}

49.Write a c program to draw the given pattern.


1
12
123
1234
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("1\n");
printf("1 2\n");
printf("1 2 3\n");
printf("1 2 3 4\n");
getch();
}
50.Write a c program to draw the given pattern.
1
22
333
4444
55555
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("1\n");
printf("2 2\n");
printf("3 3 3\n");
printf("4 4 4 4\n");
printf("5 5 5 5 5\n");
getch();
}
51. Write a c program to draw the given pattern.
1
23
456
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("1\n");
printf("2 3\n");
printf("4 5 6\n");
printf("7 8 9 10\n");
getch();
}
52.Write a c program to draw the given pattern.
1
23
456
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" 1\n");
printf(" 2 3\n");
printf(" 4 5 6\n");
printf("7 8 9 10\n");
getch();
}

53. Write a c program to draw the given pattern.


*
**
***
****
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" *\n");
printf(" * *\n");
printf(" * * *\n");
printf("* * * *\n");
getch();
}

54. Write a program in C to display the n terms of square of n number and


their sum.
1 4 9 16 25
Sum= 55
#include <stdio.h>
#include<conio.h>
void main()
{
int n, i, squareSum = 0;
clrscr();
printf("Enter the number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
int square = i * i;
printf("%d ", square);
squareSum += square;
}
printf("\nSum = %d\n", squareSum);
getch();
}

55. Write a C program to check whether a given number is an Armstrong


number or not.
Input a number: 153
Output :
153 is an Armstrong number.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,arm=0,r,c;
clrscr();
printf("enter any number: ");
scanf("%d",&n);
c=n;
while(n>0)
{
r=n%10;
arm=(r*r*r)+arm;
n=n/10;
}
if(c==arm)
printf("armstrong number");
else
printf("not");
getch();
}

56. Write a c program to draw the given pattern.


A
AB
ABC
ABCD
ABCDE
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("A\n");
printf("A B\n");
printf("A B C\n");
printf("A B C D\n");
printf("A B C D E\n");
getch();
}

57. Write a c program to draw the given pattern.


*
**
***
****
*****
****
***
**
*
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*\n");
printf("* *\n");
printf("* * *\n");
printf("* * * *\n");
printf("* * * * *\n");
printf("* * * *\n");
printf("* * *\n");
printf("* *\n");
printf("*\n");
getch();
}

58 Write a c program to draw the given pattern.


*
**
***
****
*****
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" *\n");
printf(" * *\n");
printf(" * * *\n");
printf(" * * * *\n");
printf(" * * * * *\n");
getch();
}

59. Write a c program to draw the given pattern.


AAAAA
BBBB
CCC
DD
E
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("A A A A A\n");
printf("B B B B\n");
printf("C C C\n");
printf("D D\n");
printf("E\n");
getch();
}

60. Write a c program to draw the given pattern.


EEEEE
DDDD
CCC
BB
A
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("E E E E E\n");
printf("D D D D\n");
printf("C C C\n");
printf("B B\n");
printf("A\n");
getch();
}

61. Write a c program to draw the given pattern.


5
44

333
2222
11111
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" 5\n");
printf(" 4 4\n");
printf(" 3 3 3\n");
printf(" 2 2 2 2\n");
printf(" 1 1 1 1 1\n");
getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy