Anda di halaman 1dari 7

NCE@Computer Programming I

Laboratory Session#1: Basic Input and Output

Objective:-To understand the basics of input and output operations and perform simple mathematical
operations on input data for desired computations.

1. Write a Program to print the date of today in format dd-mm-yy.

2. Write a program using printf() and different escape sequences to give output as below:

First Name Middle Name Last Name Address Marks (%)


------------ ----------------- ------------ ----------- --------
3. Write a program to accept temperature in degree Celsius and convert it into Fahrenheit using Formula
F=(C*9/5)+32.

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.

1. WAP to input age of a person and print it in days.


2. WAP to read radius of a sphere and compute its Surface Area and Volume.
3. WAP to find perimeter and area of a triangle having lengths of three sides.(say user to put valid data i.e.
the sum any two sides should be greater than third one.)
4. WAP to input 6-digit integer and print sum, product and average value of its digits.
5. WAP to find the Compound Interest and Compound Amount for a given deposit in bank for n years at
the interest rate of r (a)half yearly (b)yearly.
6. WAP to display the ASCII value of a given Character.(take a character from the user using getchar()
function.)
7. Write a program to read three numbers x, y and z and to compute the values of a,b and c given by:
I) a=x+|y-z|
II) b=tan-1
III) c=(x-z)4/3

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>

Prepared by Om Prakash Mahato 1


NCE@Computer Programming I

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);
}

Prepared by Om Prakash Mahato 2


NCE@Computer Programming I

Laboratory Session#2: Decision Control Structure


Objective:-To understand the use of selective structure (if,if..else,nested if..else, else if ladder and switch
statements)in problems involving decision making.
1. Write a program to test whether a given year is leap or not.
2. Write a program to read 3 digit no and to test whether it is an Armstrong number or not.
3. Write a program to find the roots of a quadratic equation . The program must
first show whether the roots are real and unequal, real and equal or complex conjugates. In case of
complex roots, the roots must be displayed in the form x+iy, x-iy.
4. Write a program to calculate the area of triangle having 3 sides if user enters valid data otherwise
print a message mentioning invalid data.(use else-if ladder.)
5. Write a program for a departmental store to display a list of 3 items, their price lists; Accept
customers option and print the cost of the goods, when the required quantity is entered as input.
6. Write a program that reads one character and convert it into upper character case if it is lower case
and vice-versa.

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.

Prepared by Om Prakash Mahato 3


NCE@Computer Programming I

Laboratory Session#3:Repetitive Structures.


Objective:-To understand the use of repetitive structures (for, while, and do..while structures) in problems
involving repetitions.
1. Write a program to read numbers entered by the user until the user enters zero and to find the
average of all positive numbers entered and average of all negative numbers entered.
2. Write a program to compute Mean and Standard Deviation for given N data.
3. Write a Program to print the ASCII Characters for code 32 to 255.
4. Write a program to print all Fibonacci numbers up to n.
5. Write a program to find the sum of exponential series correct up to 4 places after decimal.

ASSIGNMENT#3

1. WAP to find HCF and LCM of two given numbers.


2. To read any integer number and to print it multiplication table.
3. Write a program to find sum of odd and even numbers between n and n, where n is an
integer entered by the user.
4. Write a program to count the number of odd and even number entered by user. Your
program must read number until user enters zero. After user enters zero, display the counts.
5. Write a program to print the series 1 2 5 10 17 26 37 until the term value is less than 400.
6. Write a program to find the sum of numbers from 1 to 100 which are exactly divisible by 5
and not by 3.
7. Write a program to find the sum of sine series correct up to 4 places after decimal.
sinx=1-x3/3!+x5/5!-x7/7!+
8. Rewrite program correctly and write output of the given program written in C programming
language below:
#include stdio.h
#include conio.h
void main();
{ char c;
printf(a.Orange \t b. Apple \t c.Grape )
printf(enter you choice)
scan(%f,a);
switch(c)
{ case a printf(your choice is orance)
Case b printf(your choice is apple)
}
}

Prepared by Om Prakash Mahato 4


NCE@Computer Programming I

9. Write the output of the following programs.

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();
}

Prepared by Om Prakash Mahato 5


NCE@Computer Programming I

Laboratory Session#4:User-Defined Function

Objective: To understand the use of functions in a program.

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

1. Write a program to find square of a number using macro.


2. Write a program that finds the largest among three numbers. Use a function that returns the larger of
two numbers passed to it.
3. Write a program calculate the value of the given series using recursive function.
12-22+3 2-42 +(-1)n+1 n2 without using pow() function. You should read n from the user.
4. Write a function to calculate the combination/permutation of r numbers out of n. Your program
should read the value of r and n from the user and the choice for combination or permutation.
5. Write a function to convert a character to lower to upper or upper to lower case using Call by
Reference method.
6. Write a program to calculate the value of the given series using user defined function.

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.

Prepared by Om Prakash Mahato 6


NCE@Computer Programming I
Laboratory Session#5:Arrays and Strings.
Objective:-To understand the use of arrays for handling multiple data items of the same type.
1. Write a program to sort the numbers in either ascending or descending order using one dimensional
order.
2. Write a program to read a matrix of numbers (of given order) and to find and display its transpose.
Also determine whether the matrix is symmetric or not.
3. Write a program to read a line of text and to count the number of digits in it. Use a character array to
store the line and pass it to a function defined to return the number of digits present in the c haracter
array.
4. Write a program to arrange characters in a word in alphabetical order.
5. Write a program that prompts the user for two strings, assemble them into a single string and then
print the string in reversed.
ASSIGNMENT#5

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
}

Prepared by Om Prakash Mahato 7

Anda mungkin juga menyukai