Chakka Karthikeya 256
Chakka Karthikeya 256
Using C Lab
Example:12510=(1111101)
BINARY To DECIMAL: multiplying each digit of binary number by it’s corresponding power of
2 and adding up the result.
Example:(101011)2=(43)10
DECIMAL TO HEXAGONL:The process that converting the decimal number to it’s equivalent
hexadecimal number.
Example:(1234)10=(4D2)10
Example:(ABC)16=(2748)10
Experiment:2
Design a flowchar for a program that takes two numbers as input from the user and then
performs the following operations.
(i) Add the two numbers.
(ii) Subtract the second number from the first number.
(iii) Multipy the two numbers.
(iv) Divide the first number by the second number (ensure to handle division by zero)
The flowchart should include decision points to handle division by zero and should
clearly illustrate the flow of the program from input to output .
Experiment:3
Design a flowchart for a program that calculates the total cost of a customer shopping
Cart items, including tax and any applicable discounts. The program should have the
Following features:
(i) Prompt the user to input the prices and quantities of each item they wish to
purchase.
(ii) Calculate the subtotal by multiplying the price of each item by its quantity and
(iii) Apply any applicable discounts based on the total purchase amount. For example,
(iv) Calculate the tax on the subtotal based on a predetermined tax rate.
(vi)Display the subtotal, any discounts applied, the tax amount, and the final total cost
To the user.
You can break down the program into separate modules or functions, each
responsible
Calculation), and then integrate them into the main program flowchart.
Experiment:4
Identify and correct the syntactical errors in given program (example given below) to
make it compile and run correctly.
#include<stdio .h>
int main () {
int num1,num2
Printf(“Enter two numbers:”);
Scanf(“%d %d”,snum1snum2);
Sum=num1+num2;
Printf(“The sum is:%d”,sum);
Return 0;
}
Experiment:5 Identify and correct the semantic errors in a given program (example given
below) to make it compile and run correctly .
#include<stdio.h>
int main () {
int num1,num2,num3,sum;
Float average;
Printf(“Enter three numbers”);
Scanf(“%d %d %d”,snum1,snum2,snum3);
Sum=num1+num2-num3;
Average =sum/2;
Printf(“The average is:%.2f”, average);
Return 0;
}
Experiment:6
Write a c program that takes an integer as input from the user and prints whether the
number is positive, negative,or zero.additionally,if the number is positive,check if it’s even
or odd and print that information as well.
Experiment:7 write a c program to implement a simple guessing game.The should generate
a random number between 1 and 100(inclusive)and prompt the user to guess the
number.After each guess,the program should provide feedback to the user,indicating
whether the guess is too high,too low,or correct.The user should continue guessing until
they correctly identify the random number.Additionality,limit the number of guesses to
10,and if the user exceeds this limit without guessing the correct number,display a message
indicating that they have lost the game
Experiment:8. Write a c program that calculates the value of a mathematical expression
involving trigonometric functions and logarithms.The program should prompt the user to
input the value of variable and evaluate the expression.Ensure to handle error cases such
as division by zero or undefined values.sample mathematical expression to evaluate:
Sin(x)+cos(y)/log(z)
Experiment:G. Write a C program that calculates the factorial of a non-negative integer
using recursion.The factorial of non-negative integer n,denoted as n!,is the product of all
positive integers less than or equal to n.The factorial of n is defined as:
n!=n*(n-1)*(n-2)*..*3*2*1
Experiment:10.
Write a c program with an algorithm and flowchart to make a simple calculator
performing +,-,/,* using switch-case.The program takes two integer operands and one
operators from the user,performs the operation and then prints the result.
Experiment:11.
Write a C program that defines macros for mathematical operations(e.g, addition,
subtraction, multiplication,division) and uses them to performs calculations.The program
should use macros to define the operations and then demonstrate their usage in various
mathematical operations.
Experiment:12. The fibonacci sequence is a series of numbers where each number where
each number is the sum of the two preceding ones, usually starting with 0 and 1:
0,1,1,2,3,5,8,13,21,34..
Write a C program to generate the first 20 terms of the fibonacci sequence and print them.
Experiment:13. Write a C program that calculates the factorial of a given number using a
separate function for the factorial .The program should prompt the user to enter a non-
negative integer , calculate it’s factorial function,and then print the result
Experiment:15. Write a C program to calculate the average of a set of numbers.The program
should prompt the user to enter the number of elements in the set,then prompt the user to
enter each element .finally,the program should calculate and print the average of the entered
numbers using separate functions for input, calculations,and output.Additionally,use an
external variable to keep track of the sum of the numbers.
Experiment:16.
Write the C program that defines a function to count the number of vowels in a string
using character pointers.The program should prompt the user to input a string,call the
function to count the vowels,and then print out count .
Experiment:17. Write a C program that defines a function to swap the values of two integers
using pointers.The program should prompt the user to input two integers ,call the swap
function to swap their values, and then print the swapped values.
Experiment:18.write a C program that simulates a simple banking system.The program
should include the following functionalities:
a. Deposit : Allow the user to deposit a certain amount into their account.
b. Withdraw: Allow the user to withdraw a certain amount into their account.
c. Check balance: Display the current balance in the account.
d. Use static varibles to keep track of the total balance across all
transactions.Ensure that the total is shared among all instances of the
banking system.
Experiment:1G. Write a C program that takes an array of integers as input , calculates the
sum and average of the elements using pointers,and then prints the sum and average.
Experiment:20.
Write a C program that takes two n*n matrix as input from the user, calculate the product
of the matrices and prints it.
Experiment:21. Write a C program that simulates a simple text editor.The program
should allow the user to perform the following operations on a text string:
a. Append: Append a string to the end of the current text.
b. Insert:Insert a string at a specific position in the current text.
c. Delete: Delete a substring from the current text.
d. Replace: Replace a substring in the current text with another string.
e. Print: print the current text.
Experiment:22 .write a C program that implements a recursive function to generate all
possible combinations of a given set of characters.The program should take a string of
characters as input and print all possible combinations of those characters.For
example:given the input string “ABC”,the program should generate the following
combinations.
a. ABC
b. ACB
c. BAC
d. BCA
e. CAB
f. CBA
Experiment:23 . Write a C program that defines a structure called student to store the
details of a student including name, roll number and marks in three subjects (Physics,
chemistry and mathematics) The program should prompt the user to input the details
of three students store them in an array of students structure and then print the
details of all.
Experiment:24.write a C program that defines a structure called book to store tha
details of book including title author and price.The program should then create an
array of book structures to store the details of three books after storeing the details
the program should print the details of all books
Experiment:25. Write a C program that defines a structure called Employee to store the
details of an employee including name,ID,and salary.The program should then create a
pointer to an employee structure and allocate memory for it dynamically using
malloc().After allocating memory, prompt the user to input the details of an employee using
the pointer,and then print the details of the employee.
Experiment:26. Write a C program that simulates a simple online shopping system.The
program should include the following functionalities :
a. Add item to cart:Allow the user to add items to their shopping cart.
b. Remove item from cart: Allow the user to remove items from their shopping cart.
c. View cart: Display the items currently in the user shopping cart.
Ensure that each user has their own shopping cart,and use local varibles to
represent the items in the cart.
Experiment:27.write a C program that defines a union called Data to represent a data structure
that can Store either an integer or a. Floating -point number.Additionally,define a structure
called bitfield to represent a data structure that stores a set of bit -field including a flag ,an
integer value,and a floating -point value.Then the program should create varibles of types data
and bitfield,initialize them with some values,and print their contents
Experiment:28.write a C program that defines a datatype for structure called point to
represent a point in 2D space .The structure should have two members:x and y , representing
the coordinates of the point.Then, the program should create a variable of type point and
initialize it with some vaules.Finally ,it should print the coordinates of the point.