SlideShare a Scribd company logo
1 of 13
Download to read offline
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

Cache performance considerations
Cache performance considerationsCache performance considerations
Cache performance considerationsSlideshare
 
Integrated service digital network
Integrated service digital networkIntegrated service digital network
Integrated service digital networkRahul Karn
 
Shuffle exchange networks
Shuffle exchange networksShuffle exchange networks
Shuffle exchange networksLahiru Danushka
 
Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Anshul gour
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formatsMazin Alwaaly
 
Routing protocols for ad hoc wireless networks
Routing protocols for ad hoc wireless networks Routing protocols for ad hoc wireless networks
Routing protocols for ad hoc wireless networks Divya Tiwari
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSDr. SELVAGANESAN S
 
Join ordering in fragment queries
Join ordering in fragment queriesJoin ordering in fragment queries
Join ordering in fragment queriesIfzalhussainkhan
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemPoojaBele1
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dosvanamali_vanu
 
Client server computing
Client server computingClient server computing
Client server computingStudent
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure callsAshish Kumar
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLjunnubabu
 

What's hot (20)

Cache performance considerations
Cache performance considerationsCache performance considerations
Cache performance considerations
 
Integrated service digital network
Integrated service digital networkIntegrated service digital network
Integrated service digital network
 
Shuffle exchange networks
Shuffle exchange networksShuffle exchange networks
Shuffle exchange networks
 
Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)
 
Computer architecture addressing modes and formats
Computer architecture addressing modes and formatsComputer architecture addressing modes and formats
Computer architecture addressing modes and formats
 
Cs8591 Computer Networks
Cs8591 Computer NetworksCs8591 Computer Networks
Cs8591 Computer Networks
 
Hdlc
HdlcHdlc
Hdlc
 
Routing protocols for ad hoc wireless networks
Routing protocols for ad hoc wireless networks Routing protocols for ad hoc wireless networks
Routing protocols for ad hoc wireless networks
 
Pawan111
Pawan111Pawan111
Pawan111
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
 
Join ordering in fragment queries
Join ordering in fragment queriesJoin ordering in fragment queries
Join ordering in fragment queries
 
Wap wml
Wap wmlWap wml
Wap wml
 
Remote Procedure Call in Distributed System
Remote Procedure Call in Distributed SystemRemote Procedure Call in Distributed System
Remote Procedure Call in Distributed System
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
 
IEEE 802.11
IEEE 802.11IEEE 802.11
IEEE 802.11
 
Client server computing
Client server computingClient server computing
Client server computing
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure calls
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROL
 
Email and DNS
Email and DNSEmail and DNS
Email and DNS
 
Distributed database
Distributed databaseDistributed database
Distributed database
 

Similar to C - Programming Assignment 1 and 2

C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation filesantoshkumarhpu
 
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.docxwhitneyleman54422
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy BookAbir 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 newLast7693
 
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 newscottbrownnn
 
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 neweyavagal
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01Drjilesh
 
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).pdfjanakim15
 
best notes in c language
best notes in c languagebest notes in c language
best notes in c languageIndia
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
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.docxABDULAHAD507571
 
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 languagesushma 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.docxAASTHA76
 

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 and frameworks
Cloud platforms and frameworksCloud platforms and frameworks
Cloud platforms and frameworksAnimesh Chaturvedi
 
Cloud service lifecycle management
Cloud service lifecycle managementCloud service lifecycle management
Cloud service lifecycle managementAnimesh 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 answersAnimesh Chaturvedi
 
Advance Systems Engineering Topics
Advance Systems Engineering TopicsAdvance Systems Engineering Topics
Advance Systems Engineering TopicsAnimesh 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-HardAnimesh 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 solutionsAnimesh Chaturvedi
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 
System requirements engineering
System requirements engineeringSystem requirements engineering
System requirements engineeringAnimesh Chaturvedi
 
Introduction to Systems Engineering
Introduction to Systems EngineeringIntroduction to Systems Engineering
Introduction to Systems EngineeringAnimesh Chaturvedi
 
Big Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingBig Data Analytics and Ubiquitous computing
Big Data Analytics and Ubiquitous computingAnimesh Chaturvedi
 
Cloud Platforms and Frameworks
Cloud Platforms and FrameworksCloud Platforms and Frameworks
Cloud Platforms and FrameworksAnimesh Chaturvedi
 
Cloud Service Life-cycle Management
Cloud Service Life-cycle ManagementCloud Service Life-cycle Management
Cloud Service Life-cycle ManagementAnimesh 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

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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