SlideShare a Scribd company logo
Lab Assignment 1: Introduction to C Programming
CS-153 Computer Programming Lab
Autumn Semester, 2016, IIT Indore
Date: 01-08-16
Introduction to #include, printf, scanf, variables, expression, if statement, if else statement, main(),
return() and data types: integer, float, and char. Introduction to programming standards: Line length
limit, Comments, Variable names, Indentation, Braces, Position of main ( ), Declarations, Position of
variable declarations.
Note: Write following programs in C language. Also note that this assignment will be evaluated by
TA’s in the upcoming labs of next week (08-08-16 onward) for each batch.
1. Write a program to print “Hello World” on screen.
2. Write a program to input two integers and print their sum.
3. Write a program to input length and breadth of a rectangle. Calculate and print area and perimeter of
the rectangle.
4. Write a program to input a number and print whether it is odd or even.
5. Write a program to input a 5-digit integer through keyboard, and obtain the reverse number. Print
whether the original and reverse numbers are equal or not. If not, print the greater one.
6. If cost price and selling price of an item is input through the keyboard, write a program to determine
whether the seller has made profit or incurred loss. Also determine how much profit he made or loss
he incurred.
7. If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the
youngest of the three.
8. Write a program to find the greatest of the three numbers entered through the keyboard using
conditional operators.
9. Write a program to find the value of one number raised to the power of another.
10. Write a program to print all the ASCII values and their equivalent characters using a while loop. The
ASCII values vary from 0 to 255.
Lab Assignment 2: Loops, Case Control and Array: C Programming
CS-153 Computer Programming Lab
Autumn Semester, 2016, IIT Indore
Date: 09-08-16
Note: Write following programs in C language. Also note that this assignment will be evaluated by
TA’s in the upcoming labs of next week (15-08-16 onward) for each batch.
1. Write a program to compute an integer y such that y is produced by reversing x (using loop). For
example, if x is 6787, y is 7876, and if x is 80, y is 8.
2. Fibonacci numbers are the numbers in the following integer sequence: 0,1,1,2,3,5,8,13,21... By
definition, the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the
previous two numbers. Write a program (using loop) to compute nth number in this series for given
input n.
3. Write a menu driven program (using switch case) which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
4. Write a program to find average marks (using array) obtained by a class of 30 students in a test.
5. Write a program to find out the frequency of occurrence of a given value v inside an array of size N.
Read N, the actual numbers in the array, and value v from the keyboard before you compute the
frequency.
6. Given an array of integers of size n, find out if the numbers in the array appear in a palindrome order.
A palindrome is a sequence that reads the same when you flip it. For example, 121 is a palindrome, 3
is a palindrome, and 234432 is also a palindrome
Practice Set 1: Introduction to C Programming
CS-153 Computer Programming Lab
Autumn Semester, 2016, IIT-Indore
A control statement determines whether other statements will be executed or not. Example of control
statements are if statement, loop statements (while, do-while and for) and switch statement.
Section 1: if, if-else, nested if-else
1. Given the length and breadth of a rectangle, write a program to find whether the area of the
rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and
breadth = 4 is greater than its perimeter. Given three points (x1, y1), (x2, y2) and (x3, y3), write a
program to check if all the three points fall on one straight line.
2. Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will
determine whether a point lies inside the circle, on the circle or outside the circle.
(Hint: Use sqrt( ) and pow( ) functions).
3. Any character is entered through the keyboard; write a program to determine whether the
character entered is a capital letter, a small case letter, a digit or a special symbol. The following
table shows the range of ASCII values for various characters.
Characters ASCII Values
A – Z 65 – 90
a – z 97 – 122
0 – 9 48 – 57
special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127
4. An Insurance company follows following rules to calculate premium.
a. If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a
city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed
Rs. 2 lakhs.
b. If a person satisfies all the above conditions except that the sex is female then the premium is
Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
c. If a person’s health is poor and the person is between 25 and 35 years of age and lives in a
village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs.
10,000.
d. In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her premium
rate and maximum amount for which he/she can be insured.
5. A certain grade of steel is graded according to the following conditions:
a. Hardness must be greater than 50
b. Carbon content must be less than 0.7
c. Tensile strength must be greater than 5600
The grades are as follows:
Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon content
and tensile strength of the steel under consideration and output the grade of the steel.
6. A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10
days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days
your membership will be cancelled. Write a program to accept the number of days the member is
late to return the book and display the fine or the appropriate message.
7. If the three sides of a triangle are entered through the keyboard, write a program to check whether
the triangle is isosceles, equilateral, scalene or right angled triangle.
8. In a company, worker efficiency is determined on the basis of the time required for a worker to
complete a particular job. If the time taken by the worker is between 2–3 hours, then the worker is
said to be highly efficient. If the time required by the worker is between 3–4 hours, then the
worker is ordered to improve speed. If the time taken is between 4–5 hours, the worker is given
training to improve his speed, and if the time taken by the worker is more than 5 hours, then the
worker has to leave the company. If the time taken by worker is input through the keyboard, find
the efficiency of the worker.
9. A university has the following rules for a student to qualify for a degree with A as the main
subject and B as the subsidiary subject:
a. He should get 55 percent or more in A and 45 percent or more in B.
b. If he gets than 55 percent in A, he should get 55 percent or more in B. However, he should get
at least 45 percent in A.
c. If he gets less than 45 percent in B and 65 percent or more in A, he is allowed to reappear in an
examination in B to qualify.
d. In all other cases he is declared to have failed. Write a program to receive marks in A and B
and Output whether the student has passed, failed or is allowed to reappear in B.
10. Policy followed by a company to process customer orders is given by the following rules:
a. If a customer order is less than or equal to that in stock and has credit is OK, supply has
requirement.
b. If has credit is not OK do not supply. Send him intimation.
c. If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate
to him data the balance will be shipped.
Write a C program to implement the company policy.
Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
Section 2: Conditional operators (? :) is a ternary operator which takes three operands
1. What would be the output of the following programs:
(a) main() {
int i = -4, j, num;
j = (num < 0 ? 0 : num * num);
printf("n%d", j);
}
(b) main() {
int k, num = 30;
k = (num > 5 ? (num <= 10 ? 100 : 200) : 500);
printf("n%d", num);
}
(c) main() {
int j = 4;
(!j != 1 ? printf("nWelcome") : printf("nGood Bye"));
}
2. Rewrite the following programs using conditional operators.
(a) main() {
int x, min, max;
scanf("n%d %d", & max, & x);
if (x > max) {
max = x;
} else {
min = x;
}
}
(b) main() {
int code;
scanf("%d", & code);
if (code > 1) {
printf("nJerusalem");
} else if (code < 1) {
printf("nEddie");
} else {
printf("nC Brain");
}
}
(c) main() {
float sal;
printf("Enter the salary");
scanf("%f", & sal);
if (sal < 40000 && sal > 25000) {
printf("Manager");
} else {
if (sal < 25000 && sal > 15000) {
printf("Accountant");
} else { printf("Clerk");
}
}
}
3. Using conditional operators determine:
a. Whether the character entered through the keyboard is a lower case alphabet or not.
b. Whether a character entered through the keyboard is a special symbol or not.
4. Write a program using conditional operators to determine whether a year entered through the
keyboard is a leap year or not.
Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
Section 3: for and/or while
1. Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs.
12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for
fractional part of an hour.
2. Write a program to find the factorial value of any number entered through the keyboard. Two
numbers are entered through the keyboard.
3. Write a program to find the value of one number raised to the power of another.
4. Write a program to print all the ASCII values and their equivalent characters using a while loop.
The ASCII values vary from 0 to 255.
Section 4: loop that needs do-while, break and/or continue
1. An expression contains relational operators, assignment operators, and arithmetic operators. In
the absence of parentheses, they will be evaluated in which of the following order:
1. assignment, relational, arithmetic
2. arithmetic, relational, assignment
3. relational, arithmetic, assignment
4. assignment, arithmetic, relational
2. The break statement is used to exit from:
1. an if statement
2. a for loop
3. a program
4. the main( ) function
3. A do-while loop is useful when we want that the statements within the loop must be executed:
1. Only once
2. At least once
3. More than once
4. None of the above
4. In what sequence the initialization, testing and execution of body is done in a do-while loop
1. Initialization, execution of body, testing
2. Execution of body, initialization, testing
3. Initialization, testing, execution of body
4. None of the above.
5. Write a program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and
continue)
6. Write a program to fill the entire screen with a smiling face. Smiling face has an ASCII value 1.
Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
#include <stdio.h>
int main()
{
int num = 6787;
int rev_num = 0;
while(num > 0)
{
rev_num = rev_num*10 + num%10;
num = num/10;
}
printf("Reverse of no. is %d", rev_num);
getchar();
return 0;
}
/*
* C program to generate and print first N FIBONACCI numbers
* in the series.
*/
#include <stdio.h>
void main()
{
int fib1 = 0, fib2 = 1, fib3, num, count = 0;
printf("Enter the value of num n");
scanf("%d", &num);
printf("First %d FIBONACCI numbers are ...n", num);
printf("%dn", fib1);
printf("%dn", fib2);
count = 2; /* fib1 and fib2 are already used */
while (count < num)
{
fib3 = fib1 + fib2;
count++;
printf("%dn", fib3);
fib1 = fib2;
fib2 = fib3;
}
}
main( )
{
int choice ;
while ( 1 )
{
printf ( "n1. Factorial" ) ;
printf ( "n2. Prime" ) ;
printf ( "n3. Odd/Even" ) ;
printf ( "n4. Exit" ) ;
printf ( "nYour choice? " ) ;
scanf ( "%d", &choice ) ;
switch ( choice )
{
case 1 :
/* logic for factorial of a number */
break ;
case 2 :
/* logic for deciding prime number */
break ;
case 3 :
/* logic for odd/even */
break ;
case 4 :
exit( ) ;
}
}
}
#include<stdio.h>
main( )
{
int avg, sum = 0 ;
int i ;
int marks[30] ; /* array declaration */
for ( i = 0 ; i <= 29 ; i++)
{
printf ( "nEnter marks " ) ;
scanf ( "%d", &marks[i] ) ; /* store data in array */
}
for ( i = 0 ; i <= 29 ; i++ )
sum = sum + marks[i] ; /* read data from an array*/
avg = sum / 30 ;
printf ( "nAverage marks = %d", avg ) ;
}
#include<stdio.h>
int main()
{
int array[];
int i, N, v, frequency=0;
printf("Enter the size of the arrayn");
scanf("%d",&N);
printf("Enter %d numbersn", N);
for(i=0;i<N;i++)
{
scanf("%d",&array[i]);
}
printf("Enter the value for which frequency is to be computedn");
scanf("%d", &v);
for(i=0; i<N; i++)
{
if(array[i]==v)
{
frequency++;
}
}
printf("The frequency is %d", frequency);
}
#include<stdio.h>
#include<conio.h>
int main()
{
int n, reverse = 0, temp;
printf("Enter a number to check if it is a palindrome or notn");
scanf("%d",&n);
temp = n;
while( temp != 0 ) // temp is descreases with least significant digit.
{
reverse = reverse * 10; // reverse is multiplied with 10.
reverse = reverse + temp%10; // find out the least significant digit to add with
the reverse. Store the value in reverse again.
temp = temp/10; // temp is descreased with a least significant digit.
}
if ( n == reverse ) // if given number n is equal to reverse then
palindrome otherwise not.
printf("%d is a palindrome number.n", n);
else
printf("%d is not a palindrome number.n", n);
getch();
return 0;
}

More Related Content

What's hot

Cellular network
Cellular networkCellular network
Cellular networkMr SMAK
 
Ec8491 Communication Theory-Unit 1 - Amplitude Modulation
Ec8491 Communication Theory-Unit 1 - Amplitude ModulationEc8491 Communication Theory-Unit 1 - Amplitude Modulation
Ec8491 Communication Theory-Unit 1 - Amplitude Modulation
NimithaSoman
 
Large scale path loss 1
Large scale path loss 1Large scale path loss 1
Large scale path loss 1
Vrince Vimal
 
Wireless communication
Wireless communicationWireless communication
Wireless communication
Mukesh Chinta
 
Wt module 2
Wt module 2Wt module 2
Wt module 2
Karan Thakkar
 
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMSFIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
Dr. Ghanshyam Singh
 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
 
1. introduction to wireless communication
1. introduction to wireless communication1. introduction to wireless communication
1. introduction to wireless communication
JAIGANESH SEKAR
 
FHSS- Frequency Hop Spread Spectrum
FHSS- Frequency Hop Spread SpectrumFHSS- Frequency Hop Spread Spectrum
FHSS- Frequency Hop Spread Spectrum
Rohit Choudhury
 
Error correction error detection in digital communication
Error correction error detection in digital communicationError correction error detection in digital communication
Error correction error detection in digital communication
swatihalunde
 
Cyclic code systematic
Cyclic code systematicCyclic code systematic
Cyclic code systematic
Nihal Gupta
 
Wireless traffic theory and handoff
Wireless traffic theory and handoffWireless traffic theory and handoff
Wireless traffic theory and handoff
Munaf Rashid
 
Chapter#5
Chapter#5Chapter#5
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
Amr E. Mohamed
 
GSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency ReuseGSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency Reuse
sanjida2222
 
Chapter 2 signals and spectra,
Chapter 2   signals and spectra,Chapter 2   signals and spectra,
Chapter 2 signals and spectra,nahrain university
 
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
Antenna Manufacturer Coco
 
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
Bharat Chandra Sahu
 

What's hot (20)

Cellular network
Cellular networkCellular network
Cellular network
 
Ec8491 Communication Theory-Unit 1 - Amplitude Modulation
Ec8491 Communication Theory-Unit 1 - Amplitude ModulationEc8491 Communication Theory-Unit 1 - Amplitude Modulation
Ec8491 Communication Theory-Unit 1 - Amplitude Modulation
 
Large scale path loss 1
Large scale path loss 1Large scale path loss 1
Large scale path loss 1
 
Wireless communication
Wireless communicationWireless communication
Wireless communication
 
1 6
1 61 6
1 6
 
Wt module 2
Wt module 2Wt module 2
Wt module 2
 
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMSFIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
FIXED TELEPHONE, MOBILE TELEPHONE AND SATELLITE COMMUNICATION SYSTEMS
 
L11 array list
L11 array listL11 array list
L11 array list
 
1. introduction to wireless communication
1. introduction to wireless communication1. introduction to wireless communication
1. introduction to wireless communication
 
FHSS- Frequency Hop Spread Spectrum
FHSS- Frequency Hop Spread SpectrumFHSS- Frequency Hop Spread Spectrum
FHSS- Frequency Hop Spread Spectrum
 
Error correction error detection in digital communication
Error correction error detection in digital communicationError correction error detection in digital communication
Error correction error detection in digital communication
 
Cyclic code systematic
Cyclic code systematicCyclic code systematic
Cyclic code systematic
 
Wireless traffic theory and handoff
Wireless traffic theory and handoffWireless traffic theory and handoff
Wireless traffic theory and handoff
 
Chapter#5
Chapter#5Chapter#5
Chapter#5
 
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and SystemsDSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
DSP_FOEHU - Lec 02 - Frequency Domain Analysis of Signals and Systems
 
GSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency ReuseGSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency Reuse
 
Chapter 2 signals and spectra,
Chapter 2   signals and spectra,Chapter 2   signals and spectra,
Chapter 2 signals and spectra,
 
Convolution Codes
Convolution CodesConvolution Codes
Convolution Codes
 
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
55 Different Types of Antennas With Examples Used in Wireless Communication.pdf
 
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
In sight into wavelets from theory to practice , soman k.p. ,ramachandran k.i...
 

Similar to C - Programming Assignment 1 and 2

Java Practice Set
Java Practice SetJava Practice Set
Java Practice Set
Gaurav Dixit
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
santoshkumarhpu
 
Statement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docxStatement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docx
whitneyleman54422
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
Abir Hossain
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
rajni kaushal
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
Last7693
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
scottbrownnn
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
eyavagal
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
Drjilesh
 
Mmt 001
Mmt 001Mmt 001
Mmt 001
sujatam8
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
itprasad1237
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
janakim15
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
India
 
If switch structure
If switch structureIf switch structure
If switch structure
M Sagheer Malik
 
Conditional structure
Conditional structureConditional structure
Conditional structure
International Islamic University
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
shyamuopeight
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
ABDULAHAD507571
 
programming for programs solving using C language
programming for  programs solving using C languageprogramming for  programs solving using C language
programming for programs solving using C language
sushma chinta
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
AASTHA76
 

Similar to C - Programming Assignment 1 and 2 (20)

Java Practice Set
Java Practice SetJava Practice Set
Java Practice Set
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
 
Statement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docxStatement of Operations and Financial StatementsSubmit written r.docx
Statement of Operations and Financial StatementsSubmit written r.docx
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
Mmt 001
Mmt 001Mmt 001
Mmt 001
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c language
 
If switch structure
If switch structureIf switch structure
If switch structure
 
Conditional structure
Conditional structureConditional structure
Conditional structure
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
Python programs
Python programsPython programs
Python programs
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
programming for programs solving using C language
programming for  programs solving using C languageprogramming for  programs solving using C language
programming for programs solving using C language
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
 

More from Animesh Chaturvedi

Cloud Platforms & Frameworks
Cloud Platforms & FrameworksCloud Platforms & Frameworks
Cloud Platforms & Frameworks
Animesh Chaturvedi
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
Animesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
Animesh Chaturvedi
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
Animesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
Animesh Chaturvedi
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
Animesh Chaturvedi
 
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Animesh Chaturvedi
 
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Animesh Chaturvedi
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
Animesh Chaturvedi
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
Animesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
Animesh Chaturvedi
 
Informatics systems
Informatics systemsInformatics systems
Informatics systems
Animesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
Animesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
Animesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
Animesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
Animesh Chaturvedi
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
Animesh Chaturvedi
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
Animesh Chaturvedi
 

More from Animesh Chaturvedi (20)

Cloud Platforms & Frameworks
Cloud Platforms & FrameworksCloud Platforms & Frameworks
Cloud Platforms & Frameworks
 
Cloud platforms and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworks
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle management
 
Graph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answersGraph Analytics and Complexity Questions and answers
Graph Analytics and Complexity Questions and answers
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering Topics
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)System Development Life Cycle (SDLC)
System Development Life Cycle (SDLC)
 
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
Shortest path, Bellman-Ford's algorithm, Dijkastra's algorithm, their Java co...
 
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
Minimum Spanning Tree (MST), Kruskal's algorithm and Prim's Algorithm, and th...
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineering
 
Informatics systems
Informatics systemsInformatics systems
Informatics systems
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems Engineering
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computing
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and Frameworks
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle Management
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

C - Programming Assignment 1 and 2

  • 1. Lab Assignment 1: Introduction to C Programming CS-153 Computer Programming Lab Autumn Semester, 2016, IIT Indore Date: 01-08-16 Introduction to #include, printf, scanf, variables, expression, if statement, if else statement, main(), return() and data types: integer, float, and char. Introduction to programming standards: Line length limit, Comments, Variable names, Indentation, Braces, Position of main ( ), Declarations, Position of variable declarations. Note: Write following programs in C language. Also note that this assignment will be evaluated by TA’s in the upcoming labs of next week (08-08-16 onward) for each batch. 1. Write a program to print “Hello World” on screen. 2. Write a program to input two integers and print their sum. 3. Write a program to input length and breadth of a rectangle. Calculate and print area and perimeter of the rectangle. 4. Write a program to input a number and print whether it is odd or even. 5. Write a program to input a 5-digit integer through keyboard, and obtain the reverse number. Print whether the original and reverse numbers are equal or not. If not, print the greater one. 6. If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred. 7. If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three. 8. Write a program to find the greatest of the three numbers entered through the keyboard using conditional operators. 9. Write a program to find the value of one number raised to the power of another. 10. Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.
  • 2. Lab Assignment 2: Loops, Case Control and Array: C Programming CS-153 Computer Programming Lab Autumn Semester, 2016, IIT Indore Date: 09-08-16 Note: Write following programs in C language. Also note that this assignment will be evaluated by TA’s in the upcoming labs of next week (15-08-16 onward) for each batch. 1. Write a program to compute an integer y such that y is produced by reversing x (using loop). For example, if x is 6787, y is 7876, and if x is 80, y is 8. 2. Fibonacci numbers are the numbers in the following integer sequence: 0,1,1,2,3,5,8,13,21... By definition, the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two numbers. Write a program (using loop) to compute nth number in this series for given input n. 3. Write a menu driven program (using switch case) which has following options: 1. Factorial of a number. 2. Prime or not 3. Odd or even 4. Exit 4. Write a program to find average marks (using array) obtained by a class of 30 students in a test. 5. Write a program to find out the frequency of occurrence of a given value v inside an array of size N. Read N, the actual numbers in the array, and value v from the keyboard before you compute the frequency. 6. Given an array of integers of size n, find out if the numbers in the array appear in a palindrome order. A palindrome is a sequence that reads the same when you flip it. For example, 121 is a palindrome, 3 is a palindrome, and 234432 is also a palindrome
  • 3. Practice Set 1: Introduction to C Programming CS-153 Computer Programming Lab Autumn Semester, 2016, IIT-Indore A control statement determines whether other statements will be executed or not. Example of control statements are if statement, loop statements (while, do-while and for) and switch statement. Section 1: if, if-else, nested if-else 1. Given the length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter. Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points fall on one straight line. 2. Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle. (Hint: Use sqrt( ) and pow( ) functions). 3. Any character is entered through the keyboard; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters. Characters ASCII Values A – Z 65 – 90 a – z 97 – 122 0 – 9 48 – 57 special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127 4. An Insurance company follows following rules to calculate premium. a. If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs. b. If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh. c. If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000. d. In all other cases the person is not insured. Write a program to output whether the person should be insured or not, his/her premium rate and maximum amount for which he/she can be insured. 5. A certain grade of steel is graded according to the following conditions: a. Hardness must be greater than 50 b. Carbon content must be less than 0.7
  • 4. c. Tensile strength must be greater than 5600 The grades are as follows: Grade is 10 if all three conditions are met Grade is 9 if conditions (i) and (ii) are met Grade is 8 if conditions (ii) and (iii) are met Grade is 7 if conditions (i) and (iii) are met Grade is 6 if only one condition is met Grade is 5 if none of the conditions are met Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel. 6. A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message. 7. If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is isosceles, equilateral, scalene or right angled triangle. 8. In a company, worker efficiency is determined on the basis of the time required for a worker to complete a particular job. If the time taken by the worker is between 2–3 hours, then the worker is said to be highly efficient. If the time required by the worker is between 3–4 hours, then the worker is ordered to improve speed. If the time taken is between 4–5 hours, the worker is given training to improve his speed, and if the time taken by the worker is more than 5 hours, then the worker has to leave the company. If the time taken by worker is input through the keyboard, find the efficiency of the worker. 9. A university has the following rules for a student to qualify for a degree with A as the main subject and B as the subsidiary subject: a. He should get 55 percent or more in A and 45 percent or more in B. b. If he gets than 55 percent in A, he should get 55 percent or more in B. However, he should get at least 45 percent in A. c. If he gets less than 45 percent in B and 65 percent or more in A, he is allowed to reappear in an examination in B to qualify. d. In all other cases he is declared to have failed. Write a program to receive marks in A and B and Output whether the student has passed, failed or is allowed to reappear in B. 10. Policy followed by a company to process customer orders is given by the following rules: a. If a customer order is less than or equal to that in stock and has credit is OK, supply has requirement. b. If has credit is not OK do not supply. Send him intimation. c. If has credit is Ok but the item in stock is less than has order, supply what is in stock. Intimate to him data the balance will be shipped. Write a C program to implement the company policy. Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
  • 5. Section 2: Conditional operators (? :) is a ternary operator which takes three operands 1. What would be the output of the following programs: (a) main() { int i = -4, j, num; j = (num < 0 ? 0 : num * num); printf("n%d", j); } (b) main() { int k, num = 30; k = (num > 5 ? (num <= 10 ? 100 : 200) : 500); printf("n%d", num); } (c) main() { int j = 4; (!j != 1 ? printf("nWelcome") : printf("nGood Bye")); } 2. Rewrite the following programs using conditional operators. (a) main() { int x, min, max; scanf("n%d %d", & max, & x); if (x > max) { max = x; } else { min = x; } } (b) main() { int code; scanf("%d", & code); if (code > 1) { printf("nJerusalem"); } else if (code < 1) { printf("nEddie"); } else { printf("nC Brain"); } }
  • 6. (c) main() { float sal; printf("Enter the salary"); scanf("%f", & sal); if (sal < 40000 && sal > 25000) { printf("Manager"); } else { if (sal < 25000 && sal > 15000) { printf("Accountant"); } else { printf("Clerk"); } } } 3. Using conditional operators determine: a. Whether the character entered through the keyboard is a lower case alphabet or not. b. Whether a character entered through the keyboard is a special symbol or not. 4. Write a program using conditional operators to determine whether a year entered through the keyboard is a leap year or not. Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
  • 7. Section 3: for and/or while 1. Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour. 2. Write a program to find the factorial value of any number entered through the keyboard. Two numbers are entered through the keyboard. 3. Write a program to find the value of one number raised to the power of another. 4. Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255. Section 4: loop that needs do-while, break and/or continue 1. An expression contains relational operators, assignment operators, and arithmetic operators. In the absence of parentheses, they will be evaluated in which of the following order: 1. assignment, relational, arithmetic 2. arithmetic, relational, assignment 3. relational, arithmetic, assignment 4. assignment, arithmetic, relational 2. The break statement is used to exit from: 1. an if statement 2. a for loop 3. a program 4. the main( ) function 3. A do-while loop is useful when we want that the statements within the loop must be executed: 1. Only once 2. At least once 3. More than once 4. None of the above 4. In what sequence the initialization, testing and execution of body is done in a do-while loop 1. Initialization, execution of body, testing 2. Execution of body, initialization, testing 3. Initialization, testing, execution of body 4. None of the above. 5. Write a program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and continue) 6. Write a program to fill the entire screen with a smiling face. Smiling face has an ASCII value 1. Reference: Questions are taken from “Let us C” by Yashwant Kanetkar
  • 8. #include <stdio.h> int main() { int num = 6787; int rev_num = 0; while(num > 0) { rev_num = rev_num*10 + num%10; num = num/10; } printf("Reverse of no. is %d", rev_num); getchar(); return 0; }
  • 9. /* * C program to generate and print first N FIBONACCI numbers * in the series. */ #include <stdio.h> void main() { int fib1 = 0, fib2 = 1, fib3, num, count = 0; printf("Enter the value of num n"); scanf("%d", &num); printf("First %d FIBONACCI numbers are ...n", num); printf("%dn", fib1); printf("%dn", fib2); count = 2; /* fib1 and fib2 are already used */ while (count < num) { fib3 = fib1 + fib2; count++; printf("%dn", fib3); fib1 = fib2; fib2 = fib3; } }
  • 10. main( ) { int choice ; while ( 1 ) { printf ( "n1. Factorial" ) ; printf ( "n2. Prime" ) ; printf ( "n3. Odd/Even" ) ; printf ( "n4. Exit" ) ; printf ( "nYour choice? " ) ; scanf ( "%d", &choice ) ; switch ( choice ) { case 1 : /* logic for factorial of a number */ break ; case 2 : /* logic for deciding prime number */ break ; case 3 : /* logic for odd/even */ break ; case 4 : exit( ) ; } } }
  • 11. #include<stdio.h> main( ) { int avg, sum = 0 ; int i ; int marks[30] ; /* array declaration */ for ( i = 0 ; i <= 29 ; i++) { printf ( "nEnter marks " ) ; scanf ( "%d", &marks[i] ) ; /* store data in array */ } for ( i = 0 ; i <= 29 ; i++ ) sum = sum + marks[i] ; /* read data from an array*/ avg = sum / 30 ; printf ( "nAverage marks = %d", avg ) ; }
  • 12. #include<stdio.h> int main() { int array[]; int i, N, v, frequency=0; printf("Enter the size of the arrayn"); scanf("%d",&N); printf("Enter %d numbersn", N); for(i=0;i<N;i++) { scanf("%d",&array[i]); } printf("Enter the value for which frequency is to be computedn"); scanf("%d", &v); for(i=0; i<N; i++) { if(array[i]==v) { frequency++; } } printf("The frequency is %d", frequency); }
  • 13. #include<stdio.h> #include<conio.h> int main() { int n, reverse = 0, temp; printf("Enter a number to check if it is a palindrome or notn"); scanf("%d",&n); temp = n; while( temp != 0 ) // temp is descreases with least significant digit. { reverse = reverse * 10; // reverse is multiplied with 10. reverse = reverse + temp%10; // find out the least significant digit to add with the reverse. Store the value in reverse again. temp = temp/10; // temp is descreased with a least significant digit. } if ( n == reverse ) // if given number n is equal to reverse then palindrome otherwise not. printf("%d is a palindrome number.n", n); else printf("%d is not a palindrome number.n", n); getch(); return 0; }