Aditya……………...
C Program 60
(1 to 10)
Q1. Write a C program to accept dimensions of a cylinder
and display the surface area and volume of cylinder.
Input-
#include <stdio.h>
int main()
{
float radius, height;
float s,v;
printf("Enter value of radius of cylinder:");
scanf("%f",&radius);
printf("Enter value of height of cylinder:");
scanf("%f",&height);
s=2*(22/7)*radius*(radius+height);
v=(22/7)*radius*radius*height;
printf("Surface area of cylinder is:%.2f\n",s);
printf("Volume of cylinder is:%.2f",v);
return 0;
}
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
………………………………………………………………………………………………………………………….
Q2. Create a structure employee (id, name, salary). Accept
details of n employees and write a menu driven program to
perform the following operations.
a)Search employee by id
b)Display all employees
Input-
#include <stdio.h>
#include <stdlib.h>
typedef struct{
char name[30];
int id;
int salary;
} Employee;
int main()
{
int i, n=2;
Employee employees[n];
printf("Enter %d Employee Details \n \n",n);
for(i=0; i<n; i++){
printf("Employee %d:- \n",i+1);
printf("Name: ");
scanf("%s",employees[i].name);
printf("Id: ");
scanf("%d",&employees[i].id);
printf("Salary: ");
scanf("%d",&employees[i].salary);
printf("\n");
}
printf("All Employees Details\n");
for(i=0; i<n; i++){
printf("Name \t: ");
printf("%s \n",employees[i].name);
printf("Id \t: ");
printf("%d \n",employees[i].id);
printf("Salary \t: ");
printf("%d \n",employees[i].salary);
printf("\n");
}
return 0;
Output-
Enter 2 Employee Details
Employee 1:-
Name: Aditya
Id: 001
Salary: 50000
Employee 2:-
Name: Shivam
Id: 002
Salary: 60000
All Employees Details
Name : Aditya
Id :1
Salary : 50000
Name : Shivam
Id :2
Salary : 60000
………………………………………………………………………………………………………………………….
Q3. Write a C program to accept radius of a circle and
display the area and circumference of a circle.
Input-
#include<stdio.h>
int main()
{
int radius;
float area,circumference;
printf("Enter radius of circle:");
scanf("%d",&radius);
area = 3.14*radius*radius;
printf("Area of circle:%f\n",area);
circumference=2*3.14*radius;
printf("Circumference of circle: %f",circumference);
return 0;
}
Output-
Enter radius of circle:2
Area of circle:12.560000
Circumference of circle: 12.560000
………………………………………………………………………………………………………………………….
Q4. Write a program to calculate sum of following series up
to n terms. Sum=X+X2/2!+X3/3!+……
(Note: Write separate user defined function to calculate
power and factorial)
Input-
#include <stdio.h>
void main()
{
float x;
float sum=1;
float number_of_rows=1;
int i,n;
printf("Enter the value of x:");
scanf("%f",&x);
printf("Enter number of terms:");
scanf("%d",&n);
for (i=1;i<n;i++)
{
number_of_rows =number_of_rows*x/(float)i;
sum =sum+number_of_rows;
}
printf("The sum is:%f\n",sum);
}
Output-
Enter the value of x:2
Enter number of terms:3
The sum is:5.000000
………………………………………………………………………………………………………………………….
Q5. Write a C program to accept temperatures in Fahrenheit
(F) and display it in Celsius(C) and Kelvin (K) (Hint:
C=5.0/9(F-32), K = C + 273.15)
Input-
#include<stdio.h>
void main()
{
float fahrenheit,convert;
printf("Enter temperature in fahrenheit:");
scanf("%f",&fahrenheit);
convert=(fahrenheit-32)*5/9;
printf("Temperature in celsius:%f",convert);
return 0;
}
Output-
Enter temperature in fahrenheit:45
Temperature in celsius:7.222222
………………………………………………………………………………………………………………………….
Q6. Write a menu driven program to perform the following
operations on strings using standard library functions:
1. Length of String
2. Copy String
3. Connect Two Strings
4. Compare two 4 strings
Input-
#include<conio.h>
#include<string.h>
#include<stdio.h>
void lengthofstring()
{
int length;
char string[20];
printf("\nEnter String: ");
scanf("%s",&string);
length=strlen(string);
printf("\nLength of string is: %d",length);
}
void copystring()
{
char string2[20];
char string[20];
printf("\nEnter String: ");
scanf("%s",&string);
strcpy(string2,string);
printf("\nCopied string is: %s",string2);
}
void add()
{
char string2[20];
char string[20];
char string3[20];
printf("\nEnter 1st String: ");
scanf("%s",&string);
printf("\nEnter 2nd String: ");
scanf("%s",&string2);
printf("\nAddition of 2 string: %s",strcat(string,string2));
}
void compare()
{
char string2[20];
char string[20];
printf("\nEnter 1st String: ");
scanf("%s",&string);
printf("\nEnter 2nd String: ");
scanf("%s",&string2);
if(strcmp(string,string2)==0)
{
printf("\nBoth are equal");
}
else
{
printf("\nBoth are different");
}
}
void main()
{
int c;
do
{
printf("\n\n1. Length of string\n2. Copy String \n3. Connect Two Strings
\n4. Compare two strings\n5. Exit\nEnter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:lengthofstring();break;
case 2:copystring();break;
case 3:add();break;
case 4:compare();break;
}
}while(c<5);
}
Output-
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:1
Enter String: Aditya
Length of string is: 6
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:2
Enter String: Aditya
Copied string is: Aditya
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:3
Enter 1st String: Aditya
Enter 2nd String: Ingale
Addition of 2 string: AdityaIngale
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:4
Enter 1st String: Aditya
Enter 2nd String: Ingale
Both are different
1. Length of string
2. Copy String
3. Connect Two Strings
4. Compare two strings
5. Exit
Enter your choice:5
………………………………………………………………………………………………………………………….
Q7. Write a C program to accept two numbers and print
arithmetic and harmonic mean of the two numbers
(Hint: AM= (a+b)/2 ,HM = ab/(a+b) )
Input-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float AM, HM;
printf("Enter the 1st number:");
scanf("%d",&a);
printf("Enter the 2nd number:");
scanf("%d",&b);
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
………………………………………………………………………………………………………………………….
Q8. Create a structure Student (id, name, marks). Accept
details of n students and write amenu driven program to
perform the following operations.
a) Search student by id
b) Display all students
Input-
#include <stdio.h>
struct student
{
char name[50];
int ID;
float marks;
} s;
int main()
{
printf("Enter Information:\n");
printf("Enter name:");
fgets(s.name,sizeof(s.name),stdin);
printf("Enter ID:");
scanf("%d",&s.ID);
printf("Enter marks:");
scanf("%f",&s.marks);
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;
printf("Enter length of the cuboid:");
scanf("%f",&length);
printf("Enter breadth of the cuboid:");
scanf("%f",&breadth);
printf("Enter height of the cuboid:");
scanf("%f",&height);
printf("______________________________________________");
surfacearea=2*(length*breadth+length*height+breadth*height);
volume=length*breadth*height;
printf("\nSurface area of cuboids is:%.2f\n",surfacearea);
printf("Volume of cuboids is:%.2f",volume);
return 0;
}
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
………………………………………………………………………………………………………………………….
Q10.Write a program which accepts a sentence from the
user and alters it as follows: Every space is replaced by *,
case of all alphabets is reversed, digits are replaced by ?
Input-
#include<stdio.h>
#include<ctype.h>
#include<string.h>
void Stral(char str[])
{
int i;
for(i=0;i<=strlen(str)-1;i++)
{
if(str[i]==' ')
str[i]='*';
if(islower(str[i]))
str[i]=toupper(str[i]);
else
str[i]=tolower(str[i]);
if(isdigit(str[i]))
str[i]='?';
}
printf("The Replacement is.....\n");
printf(" %s \n",str);
}
void main()
{
char str[100];
printf("Enter any sentence:");
fgets(str,100,stdin);
Stral(str);
}
Output-
Enter any sentence:Iam I an m a good boy54665444545
The Replacement is.....
i*AM*A*GOOD*BOY???????????
Aditya
---------------------------------------------------------------------------------------------------------