Professional Documents
Culture Documents
Laboratory Session1 5
Laboratory Session1 5
Objective:-To understand the basics of input and output operations and perform simple mathematical
operations on input data for desired computations.
2. Write a program using printf() and different escape sequences to give output as below:
4. Write a Program to read base radius and vertical height of Cylinder and compute its base area, curve surface
area and Volume.
5. Write a program to take seconds as input and display it in hour, minute and seconds in Hr:Mn:Sc format.
ASSIGNMENT#1
B. Write algorithm , draw flowcharts and write the Source code for following programs.
8. Write program to read lowercase and convert into uppercase and vice versa.(use toupper and to tolower
library functions; include header file ctype.h).
9. Calculate the functional values as follows:
a) f1= (x3+y3+z3)2
b) f2= (x+y)2-z2-2xyz+e (x-y)
c) f3= tan(x)+sin-1(x)+log(z)
hint: use pow(x,3) to calculate x3, exp(x-y) to calculate e x-y, asin(x) to calculate sin-1 (x), log(z) to
calculate log(z) . also include math.h to access above library function as #include<math.h>
10. Write a program that reads a lowercase character from the keyboard and display it in uppercase on the
monitor without using toupper and tolower library functions.
11. Write a program to find the number of digits of a number. (Hints: find logarithm and put it in an integer
variable and then add 1 on it).
12. Write the program to generate the output in following format.
Enter you name: Manti
Enter your roll no,age,gender: 421,19,F
Enter your college name: National College of Engineering
Your name is :Manti
Your roll no is:421
Your age is:19
Your gender is: F
Your college name is: National College of Engineering
13. Write the output of the following program with appropriate format.
A. main ()
{ float var = 98.4182;
printf(%7.4f\n, var);
printf(%f\n, var);
printf(%7.2f\n, var);
printf(%-7.2f\n,var);
printf(%07.2f\n,var);
printf(\n);
printf(%10.2e\n, var);
printf(%12.4e\n, -var);
printf(%-10.2e\n, var);
printf(%e\n, var);
}
B. main()
{ char x=P;
char movie[20] = OM SHANTI OM;
printf(OUTPUT OF CHARACTORS\n\n);
printf(%c\n%3c\n%5c\n, x,x,x);
printf(%3c\n%c\n,x,x);
printf(\n);
printf(OUTPUT OF STRINGS\n\n);
printf(%s\n,movie) ;
printf(%20s\n,movie);
printf(%20.10s\n,movie);
printf(%.5s\n, movie);
printf(%-20.10\n,movie);
printf(%5s\n,movie);
}
ASSIGNMENT#2
1. Write a program to find the reverse of 4-digit number entered by the user. Also check
whether the number is palindrome or not.
2. Write a program to compute the values of x and y from the given two sets of linear
equations given below
Ax+By=m
Cx+Dy=n
Values of A, B, C, D, m and n should be entered by the user and display
appropriate message if AD-CB is equal to zero.
3. Write a program to determine the largest or smallest number among 3 numbers.
4. Write a program to read a character and test whether it is an alphabet or a number or special
character.
5. Read any number and check its odd/even type and display the corresponding message.
6. Menu:
1. Summation
2. Sum of squares
3. Sum of cubes
4. Product
And perform tasks per users choice.
ASSIGNMENT#3
a) #include<stdio.h>
#include<conio.h>
void main()
{
int i=1,x, num=2;
printf(\n\n\t\output\n);
printf(\n\t--------);
printf(\n);
while(num<=100)
{
x=2;
while(num%x!=0)
x++;
if(num==x)
{
printf(%d)%d\t,i,num);
i++;
}
num++;
}
getch();
}
b) #include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,num;
printf("Enter number : ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
for(k=num;k>=i;k--)
printf("%c",' ');
for(j=1;j<=i;j++)
printf("%2d",i);
printf("\n");
}
getch();
}
1. Write a program to calculate the sum natural numbers up to n entered by user using function.
2. WAP to display the following menu
Menu:
1. input radius.
2. Circumference of a circle having above radius.
3. Surface area of sphere having above radius.
4. Volume of a sphere having above radius.
5. Exit from the program.
and perform task as per users choice repeatedly until he/she chooses to exit.
3. Write a program to calculate factorial of a positive integer using
a. Programmer defined function
b. Recursive function
4. Write a function to swap the contents of the variables using call by reference method.
5. Write a program to read two values in user defined function block and calculate their sum in main function
and print result in another user defined function.
6. Write a program that reads two numbers from the user. If both the numbers are even then find their HCF else
find their LCM. The HCF and LCM should be found using two different functions. You can, however, call one of
them from other.
ASSIGNMENT#4
7. Write a program that calculates the nth Fibonacci number by using recursive function.
8. Write a progam to evaluate the sum of following series to n terms specified by the user.
x/1!-x3 /3!+x5 /5!......................where use two functions one for summation and another for
for calculating factorial. You can, however, call one of them from other.
1. Write a program to define an integer array and read n elements into it, where n is entered by
the user. Display the elements in reverse order.
2. Check whether a string entered by user is a palindrome or not and display a proper message.
(Hint: A palindrome word spells same back and forth e.g. Madam, noon)
3. Write a program to find the numbers of positive, negative, odd and even numbers is a set of
numbers.
4. Write a program to find greatest number or smallest numbers among the elements of any
given array.
5. Write a program to add/subtract two matrices after checking the order matching.
6. Write a program to multiply two 33 matrices.
7. Write a program to delete/search a given number from an array.
8. Write a program to find out octal equivalent when a decimal integer number is given.
9. Write a program to find out decimal equivalent of a given octal number.
10. Write a program to program that converts the hexadecimal number in the equivalent decimal
numbers and vice-versa using function (passing array to the function)
11. Write a program to count the words in given string using function(passing string to the
function)
12. Write a program to take names as input and make these in alphabetical order.
13. Rewrite program correctly and write output of the given program written in C programming
language below :
#include stdio.h
#include conio.h
#include string.h
void main();
{ char ar1[11]={N,a,T,I On,A,L,NCE};
char ar2[15]=TU,NCE;
clrscr();
printf(\n Array1=%c\n,ar1);
printf(\n Array2=%c\n,ar2);
return 0
}