C Program 60 (Aditya Ingale)
C Program 60 (Aditya Ingale)
C Program 60
(1 to 60)
Output-
Enter value of radius of cylinder:10
Enter value of height of cylinder:20
Surface area of cylinder is:1800.00
Volume of cylinder is:6000.00
………………………………………………………………………………………………………………………….
Output-
Enter 2 Employee Details
Employee 1:-
Name: Aditya
Id: 001
Salary: 50000
Employee 2:-
Name: Shivam
Id: 002
Salary: 60000
Name : Shivam
Id :2
Salary : 60000
………………………………………………………………………………………………………………………….
Output-
Enter radius of circle:2
Area of circle:12.560000
Circumference of circle: 12.560000
………………………………………………………………………………………………………………………….
Output-
Enter the value of x:2
Enter number of terms:3
The sum is:5.000000
………………………………………………………………………………………………………………………….
Output-
Enter temperature in fahrenheit:45
Temperature in celsius:7.222222
………………………………………………………………………………………………………………………….
Output-
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:1
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:2
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:3
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:4
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:5
………………………………………………………………………………………………………………………….
AM=((a+b))/2;
HM=a*b/((a+b));
printf("Arithmetic Mean is:%f",AM);
printf("\nHarmonic Mean is:%f",HM);
getch();
}
Output-
Enter the 1st number:10
Enter the 2nd number:20
Arithmetic Mean is:15.000000
Harmonic Mean is:6.000000
………………………………………………………………………………………………………………………….
printf("Showing Information:\n");
printf("ID:%d\n",s.ID);
printf("Name:");
printf("%s",s.name);
printf("Marks:%.2f\n",s.marks);
return 0;
}
Output-
Enter Information:
Enter name:Aditya
Enter ID:001
Enter marks:80
Showing Information:
ID:1
Name:Aditya
Marks:80.00
………………………………………………………………………………………………………………………….
Q9. Write a C program to accept dimensions length (l),
breadth(b) and height(h) of a cuboids and display surface
area and volume
(Hint : surface area=2(lb+lh+bh ), volume=lbh )
Input-
#include <stdio.h>
int main()
{
float length,breadth,height;
float surfacearea, volume;
Output-
Enter length of the cuboid:10
Enter breadth of the cuboid:20
Enter height of the cuboid:30
__________________________________
Surface area of cuboids is:2200.00
Volume of cuboids is:6000.00
………………………………………………………………………………………………………………………….
Output-
Enter any sentence:Iam I an m a good boy54665444545
The Replacement is.....
i*AM*A*GOOD*BOY???????????
………………………………………………………………………………………………………………………….
Output-
Enter the character:g
Previous character of g is f
Next character of g is h
………………………………………………………………………………………………………………………….
Output-
Enter the string:adityaingale
Enter character to be searched:a
character 'a' occurs 3 times
……………………………………………………………………………………………………………………….
Output-
Enter x1:10
Enter y1:10
Enter x2:20
Enter y2:30
Distance between the said points: 22.361
………………………………………………………………………………………………………………………….
Output-
Enter the number of row=3
Enter the number of column=3
Enter the first matrix element=
111
333
222
Enter the second matrix element=
444
222
666
Multiply of the matrix=
12 12 12
36 36 36
24 24 24
………………………………………………………………………………………………………………………….
Output-
Enter withdrow amount:156
Note of 10: 15
Note of 5: 1
Note of 1: 1
………………………………………………………………………………………………………………………….
Output-
Enter Number of rows:4
Enter Number of columns:4
Output-
Enter an alphabet:w
w is a consonant.
…………………………………………………………………………………………………………………………
return 0;
}
Output-
Enter number:7
7*1=7
7*2=14
7*3=21
7*4=28
7*5=35
7*6=42
7*7=49
7*8=56
7*9=63
7*10=70
…………………………………………………………………………………………………………………………
Output-
Enput the values for X coordinate:45
Enter the value of y coordinate:-45
The coordinate point (45,-45) lies in the Fourth quandrant.
………………………………………………………………………………………………………………………….
Q20. Write a program, which accepts a number n and
displays each digit in words. Example: 6702 Output = Six-
Seven-Zero-Two
Input-
#include<stdio.h>
int main()
{
int digit,num,n,l,r=0;
printf("Enter positive integer number:");
scanf("%d", &n);
while(n>0)
{
l=n%10;
r=r*10+l;
n=n/10;
}
num=r;
printf("\nYou entered:");
while (num>0)
{
digit=num%10;
switch(digit)
{
case 0:
printf("Zero-");
break;
case 1:
printf("One-");
break;
case 2:
printf("Two-");
break;
case 3:
printf("Three-");
break;
case 4:
printf("Four-");
break;
case 5:
printf("Five-");
break;
case 6:
printf("Six-");
break;
case 7:
printf("Seven-");
break;
case 8:
printf("Eight-");
break;
case 9:
printf("Nine-");
break;
}
num=num/10;
}
return 0;
}
Output-
Enter positive integer number:5412
You entered:Five-Four-One-Two-
………………………………………………………………………………………………………………………….
Output-
Enter cost of Pen:50
Enter selling price of Pen:45
profit=5.000000
………………………………………………………………………………………………………………………….
Option Actions
1. Area of Circle Compute area
of circle and print
2. Circumference of Circle Compute Circumference of circle and print
3. Volume of Sphere Compute Volume of Sphere and print
Input-
#include<stdio.h>
int area()
{
float r,area;
printf("\nEnter radius of circle:");
scanf("%f",&r);
area=(3.142*r*r);
printf("\nArea of Circle:%f",area);
}
int circumference()
{
float r,circumference;
printf("\nEnter radius of circle:");
scanf("%f",&r);
circumference=2*3.14*r;
printf("\nCircumference of Circle:%f",circumference);
}
int volume()
{
float r,volume_of_sphere;
printf("\nEnter radius of sphere:");
scanf("%f",&r);
volume_of_sphere=4/3*3.142*r*r;
printf("\nVolume of Sphere:%f",volume_of_sphere);
}
int main()
{
int a;
do
{
printf("\n(1) Area of Circle\n(2) Circumference of Circle\n(3) Volume
of Sphere\n(4) Exit.\n\t\tEnter choice:");
scanf("%d",&a);
switch(a)
{
case 1:area();break;
case 2:circumference();break;
case 3:volume();break;
}
}
while(a!=4);
}
Output-
(1) Area of Circle
(2) Circumference of Circle
(3) Volume of Sphere
(4) Exit.
Enter choice:1
Area of Circle:12.568000
(1) Area of Circle
(2) Circumference of Circle
(3) Volume of Sphere
(4) Exit.
Enter choice:2
Circumference of Circle:18.840000
(1) Area of Circle
(2) Circumference of Circle
(3) Volume of Sphere
(4) Exit.
Enter choice:3
Volume of Sphere:50.271999
(1) Area of Circle
(2) Circumference of Circle
(3) Volume of Sphere
(4) Exit.
Enter choice:4
………………………………………………………………………………………………………………………….
Output-
Enter a number:8795546
Sum is=44
………………………………………………………………………………………………………………………….
Q24. Accept two numbers from user and write a menu
driven program to perform the following operations
1. swap the values of two variables
2. calculate arithmetic mean and harmonic mean of two
numbers
Input-
#include <stdio.h>
int main()
{
int x, y;
float AM,HM;
printf("Enter Value of x:");
scanf("%d", &x);
printf("Enter Value of y:");
scanf("%d", &y);
int temp=x;
x=y;
y=temp;
printf("\nAfter Swapping:x=%d,y=%d\n",x,y);
AM=((x+y))/2;
HM=x*y/((x+y));
printf("Arithmetic Mean is:%f",AM);
printf("\nHarmonic Mean is:%f",HM);
return 0;
}
Output-
Enter Value of x:5
Enter Value of y:8
After Swapping:x=8,y=5
Arithmetic Mean is:6.000000
Harmonic Mean is:3.000000
………………………………………………………………………………………………………………………….
Output-
Enter the value of number:20
Sum of all odd number is:210
………………………………………………………………………………………………………………………….
int main(void)
{
int num, choice, base;
while(1)
{
printf("1.Decimal to binary.\n");
printf("2.Decimal to octal.\n");
printf("3.Decimal to hexadecimal.\n");
printf("4.Exit.\n");
printf("\n\t\t\tEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
base=2;
break;
case 2:
base=8;
break;
case 3:
base=16;
break;
case 4:
printf("Exiting ...");
exit(1);
default:
printf("Invalid choice.\n\n");
continue;
}
printf("Enter a number:");
scanf("%d", &num);
printf("Answer is=");
convert_to_x_base(num, base);
printf("\n\n");
}
return 0;
}
void convert_to_x_base(int num, int base)
{
int rem;
if (num == 0)
{
return;
}
else
{
rem = num % base;
convert_to_x_base(num/base,base);
if(base == 16 && rem >= 10)
{
printf("%c",rem+55);
}
else
{
printf("%d",rem);
}
}
}
Output-
1.Decimal to binary.
2.Decimal to octal.
3.Decimal to hexadecimal.
4.Exit.
1.Decimal to binary.
2.Decimal to octal.
3.Decimal to hexadecimal.
4.Exit.
1.Decimal to binary.
2.Decimal to octal.
3.Decimal to hexadecimal.
4.Exit.
1.Decimal to binary.
2.Decimal to octal.
3.Decimal to hexadecimal.
4.Exit.
Output-
Enter the number:45
Not Armstrong number
………………………………………………………………………………………………………………………….
Output-
Enter four digit number:4612
Odd digit:548818657
Even digit:32767
Zeros:0
………………………………………………………………………………………………………………………….
Output-
Enter a number:5
5 is not a perfect number
………………………………………………………………………………………………………………………….
2. Area of Rectangle Accept length and breadth, Compute area of rectangle and
3. Area of triangle Accept base and height , Compute area of triangle and
Input-
#include<stdio.h>
#include<conio.h>
void square()
{
float length,AOS;
printf("\nEnter length:");
scanf("%f",&length);
AOS=(length*length);
printf("\nArea of square:%f",AOS);
}
void rectangle()
{
float length,breadth,AOR;
printf("\nEnter length:");
scanf("%f",&length);
printf("\nEnter breadth:");
scanf("%f",&breadth);
AOR=length*breadth;
printf("\nArea of Rectangle:%f",AOR);
}
void triangle()
{
float height,base,AOT;
printf("\nEnter height:");
scanf("%f",&height);
printf("\nEnter base: ");
scanf("%f",&base);
AOT=(height*base)/2;
printf("\nArea of triangle: %f",AOT);
}
void main()
{
int ch;
do
{
printf("\n1)Area of Square\n2)Area of Rectangle\n3)Area of
triangle\n4)Exit.\n\t\tEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:square();break;
case 2:rectangle();break;
case 3:triangle();break;
}
}while(ch!=4);
}
Output-
1)Area of Square
2)Area of Rectangle
3)Area of triangle
4)Exit.
Enter choice:1
Enter length:8
Area of square:64.000000
1)Area of Square
2)Area of Rectangle
3)Area of triangle
4)Exit.
Enter choice:2
Enter length:6
Enter breadth:5
Area of Rectangle:30.000000
1)Area of Square
2)Area of Rectangle
3)Area of triangle
4)Exit.
Enter choice:3
Enter height:6
Enter base: 4
1)Area of Square
2)Area of Rectangle
3)Area of triangle
4)Exit.
Enter choice:4
………………………………………………………………………………………………………………………….
Output-
enter the value of x:7
enter the value of y:6
Result:117649
………………………………………………………………………………………………………………………….
Output-
Enter size of 1st array:2
Enter 1st array elements:45
63
Enter size of 2nd array:2
Enter 2nd array elements:45
89
Union of two array is:45 63 89
Intersection of two array is:45
………………………………………………………………………………………………………………………….
int main()
{
int number, i = 1;
return 0;
}
Output-
Enter the Number:5
Multiplication table of 5:
--------------------------
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
………………………………………………………………………………………………………………………….
Output-
1)Accept matrix
2)Transpose of matrix
3)sum of all odd elements of matrix
4)Exit
Enter choice:1
Enter elements:5
Enter elements:6
Enter elements:7
Enter elements:9
56
79
1)Accept matrix
2)Transpose of matrix
3)sum of all odd elements of matrix
4)Exit
Enter choice:2
57
69
1)Accept matrix
2)Transpose of matrix
3)sum of all odd elements of matrix
4)Exit
Enter choice:3
Sum of all odd elements : 21
1)Accept matrix
2)Transpose of matrix
3)sum of all odd elements of matrix
4)Exit
Enter choice:4
………………………………………………………………………………………………………………………….
Output-
Enter the number of rows:3
1
12
123
………………………………………………………………………………………………………………………….
Output-
Enter the value of x:6
Enter the value of n:2
25.000000
…………….………………………………………………………………………………………………………….
Output-
Enter the number of rows: 4
****
***
**
*
………………………………………………………………………………………………………………………….
Output-
Output-
Enter the number of rows: 3
1
23
456
………………………………………………………………………………………………………………………….
Output-
Enter the number of rows matrix:2
Enter the number of columns matrix:2
Enter the elements of first matrix:
23
56
Enter the elements of second matrix:
69
53
Sum of entered matrices:
8 12
10 9
………………………………………………………………………………………………………………………….
Output-
Enter the number of rows:4
A
AB
ABC
………………………………………………………………………………………………………………………….
Q42. Create a structure employee (eno, ename, salary).
Accept details of n employees and write a menu driven
program to perform the following operations options.
1. Display all employees having salary > 5000
2. Display all employees
Input-
#include <stdio.h>
struct employee
{
char name[30];
int empId;
float salary;
};
int main()
{
struct employee emp;
printf("\nEnter details:\n");
printf("Name:"); gets(emp.name);
printf("ID:"); scanf("%d",&emp.empId);
printf("Salary:"); scanf("%f",&emp.salary);
printf("\nEntered detail is:\n");
printf("Name:%s\n" ,emp.name);
printf("Id:%d\n" ,emp.empId);
printf("Salary:%f\n",emp.salary);
return 0;
}
Output-
Enter details:
Name:Aditya
ID:005
Salary:5 8000000
Output-
Enter the number of rows:3
ABC
AB
A
………………………………………………………………………………………………………………………….
Output-
1)Accept matrix
2)sum of all odd elements of matrix
3)Exit
Enter choice:1
Enter elements:8
Enter elements:6
Enter elements:9
Enter elements:7
86
97
1)Accept matrix
2)sum of all odd elements of matrix
3)Exit
Enter choice:2
Sum of all odd elements:16
1)Accept matrix
2)sum of all odd elements of matrix
3)Exit
Enter choice:3
………………………………………………………………………………………………………………………….
Output-
Enter size of the array:5
Enter elements in array:
45545
456
456
456
46
sum of array is:46959
………………………………………………………………………………………………………………………….
Output-
Enter size of the array:6
Enter elements in array:
4
4
8
3
1
4
maximum of array is:8
………………………………………………………………………………………………………………………….
Output-
Enter details
Name:TH he Life
NO:28
Price:5000
Output-
Enter the value of Matrix
489
Sum of all even numbers=0
………………………………………………………………………………………………………………………….
while(num > 0)
{
lastDigit = num % 10;
sum = sum + round(pow(lastDigit, digits));
num = num / 10;
}
return (originalNum == sum);
}
int isPerfect(int num)
{
int i, sum, n;
sum = 0;
n = num;
for(i=1; i<n; i++)
{
if(n%i == 0)
{
sum += i;
}
}
return (num == sum);
}
Output-
Enter any number: 5
5 is Prime number.
5 is Armstrong number.
5 is not Perfect number.
………………………………………………………………………………………………………………………….
void main()
{
char string[50];
int i, length = 0;
Output-
Enter a string
sakshi
The length of a string is the number of characters in it
So, the length of sakshi = 6
………………………………………………………………………………………………………………………….
Output-
printf("Input a string\n");
gets(s);
Output-
Input a string
you can do anything
Number of vowels in the string: 6
………………………………………………………………………………………………………………………….
Output-
Enter details
iName:Laptop
iNO:678
Price:67987
Output-
Enter the string:life is very beautiful when you only follow the way of your
dreams.
Enter character to be searched:a
character 'a' occurs 3 times
………………………………………………………………………………………………………………………….
Output-
Enter the number from 1:3
Multiplication table from 1 to 3
1x1 = 1,2x1 = 2,3x1 = 3
1x2 = 2,2x2 = 4,3x2 = 6
1x3 = 3,2x3 = 6,3x3 = 9
1x4 = 4,2x4 = 8,3x4 = 12
1x5 = 5,2x5 = 10,3x5 = 15
1x6 = 6,2x6 = 12,3x6 = 18
1x7 = 7,2x7 = 14,3x7 = 21
1x8 = 8,2x8 = 16,3x8 = 24
1x9 = 9,2x9 = 18,3x9 = 27
1x10 = 10,2x10 = 20,3x10 = 30
………………………………………………………………………………………………………………………….
Output-
Enter a positive integer: 6
Factorial of 6 = 720
………………………………………………………………………………………………………………………….
printf("%d\n", (n%10));
return 0;
}
Output-
Enter a seven digit number: 7896542
:7 8 9 6 5 4 2
………………………………………………………………………………………………………………………….
Output-
Enter a number:195635621
Sum is = 38
………………………………………………………………………………………………………………………….
Output-
Enter four digit number:8562
Odd digit:-1770259039
Even digit:32767
Zeros:0
………………………………………………………………………………………………………………………….