0% found this document useful (0 votes)
86 views

IT Lab-1

The document is a laboratory workbook for a problem solving using C course. It contains details of the student such as their name, roll number, branch, and year of study. The workbook contains a list of exercises completed by the student along with the marks received for each. It also includes rubrics for evaluating the laboratory exercises which consider factors such as preparation, observation, interpretation of results, and performance in a viva. One sample exercise is shown which involves developing C programs to process data types, operators, and expression evaluation.

Uploaded by

Fhdydh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

IT Lab-1

The document is a laboratory workbook for a problem solving using C course. It contains details of the student such as their name, roll number, branch, and year of study. The workbook contains a list of exercises completed by the student along with the marks received for each. It also includes rubrics for evaluating the laboratory exercises which consider factors such as preparation, observation, interpretation of results, and performance in a viva. One sample exercise is shown which involves developing C programs to process data types, operators, and expression evaluation.

Uploaded by

Fhdydh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

19ITSN2101 - Problem

solving using C

Laboratory

Workbook

Name
Yuvanvenkatesh G

Roll No.
20BIT030

Branch
B.Tech IT

Year/Section
2020/B Section

Semester
1st Semester

Academic Year
2020-2025
19ITSN2101 – Problem solving using C
Name : Yuvanvenkatesh G

Class : B.Tech IT

RollNo. : 20BIT030

Certified that this is bonafide record of work done by the above student
of the

during theyear

_
Head oftheDepartment StaffIn-
Charge
Submitted for the Final Assessment heldon

Internal Examiner– 1 Internal


Examiner –2

List of Exercises

S.N Dat Ti Pag Mark Facult


o e tle e s y
No. (out of Sign
75)

1 Data Types, Operators and


Expression Evaluation

2 Decision and Looping Statements

3 Arrays and Strings

4 Functions and Pointers

5 Structure and Union

6 Files and Graphics functions

Average(out of 75)

Continuous Assessment Marks – Practical (out of 10)

Signature of the Faculty


Dr.Mahalingam College of

Engineering & Technology

19ITSN2101 – Problem Solving using

Rubrics for Laboratory Exercises

Needs
Criteria Excell Good Satisfact
Improvem
ent ory
ent
Marks: Marks: Marks:15 Marks:10
20 18
Preparati Procedure for Procedure for Procedure for Procedure for
implementatio implementation implementatio implementatio
on (20 n is clearly is clearly defined n is partially n is partially
defined. with missing defined. defined with
Marks) parameters. missing
parameters.
Marks: Marks: Marks:19 Marks:15
25 23
Observati Implementation Implementation Implementation Implementat
addresses all addresses addresses most ion
on (25 requirements of almost all of the addresses
the problem requirements of requirements of few
Marks) statement. the problem the problem requirement
statement. statement. s of the
problem
statement.
Marks: Marks: Marks:10 Marks:5
Interpretation
20 15
of Result Successful Successful Successful Execution of
execution of all execution of execution of few test cases
(20 Marks)
test cases almost all test most of the
cases testcases

Marks: Marks: Marks:5 Marks:3


10 8
Viva(10 Marks)
All the questions Almost all tshe Most of the Few questions
are correctly questions are questions are are correctly
answered correctly correctly answered
answered answered
Total 75 64 49 3
Marks 3

Ex.No:1
Data Types, Operators and Expression
Date:
Evaluation
Aim:

To develop C programs to process data types, operators and expression evaluation.

Problem Statement(s) & Test case

Programs to process data types, operators and expression evaluation

• To find Area ofRectangle/Circle/Square

S.No Problem Input Expected Output


5
1
To find area of rectangle 8
112
2
4
3 To find area of circle 7
4 12
5 To find area of square 5
6 24

• To find the Simple Interest and CompoundInterest

S.No Problem Input Expected Output


P=1000
1 N=10
R=2
To find simple interest
P=1200
2 SI=(P*N*R)/100 N=2
R=5
P=2366
3 N=5
R=3
To find P=1200
4 compound interest R=5.4
CI=p*((1+r/100)t) T=2
P=2000
CI= p*pow((1+r/100),t)
5 R=2
T=3
P=5400
6 R=8
T=3

Problem Statement:

• To find Area ofRectangle/Circle/Square(Any one):

Algorithm:

Step 1:Start

Step 2: Declare variable a,b

Step 3:Get value of a (length) and b (breathe)

Step 4: Display a*b (area of rectangle)

Step 5: Stop

Flowchart:

Program:

#include<stdio.h>

#include<conio.h>

void main()

inta,b;

clrscr();
printf(“Enter Length of Rectangle : “);

scanf(“%d”,&a);

printf(“Enter Breath of Rectangle : “);

scanf(“%d”,&b);

printf(“Area of Rectangle = %d”,a*b);

getch();

Output:

• To find the Simple Interest and CompoundInterest

Algorithm:

Step 1:Start

Step 2: Declare variable p,n,r,si

Step 3:Get value of p (principal amount) , n (no.of.years) and r (rate of interest)

Step 4:Set si=(p*n*r)/100

Step 5: Display si (simple interest)

Step 6: Stop
Flowchart:

Program:

#include<stdio.h>

#include<conio.h>

void main()

intp,n,r,si;

clrscr();

printf(“Enter Principal Amount:”);

scanf(“%d”,&p);

printf(“Enter No Of Years:”);

scanf(“%d”,&n);

printf(“Enter Rate Of Intrest:”);

scanf(“%d”,&r);

si=(p*n*r)/100;

printf(“Simple Intrest = %d”,si);

getch();

Output:
• To find the CompoundInterest:

Algorithm:

Flowchart:

Program:

Output:

a. Write a program to enter a 4 digit number from keyboard. Add 8 to the


number and then divide it by 3. Now, the modulus of that number is taken
with 5 and then multiply the resultant value by 5. Display the final result.

b. If the marks of Robert in three subjects are 78,45 and 62 respectively (each
out of 100 ), write a program to calculate his total marks and percentage
marks.

c. Program to find the size of integer,character,float,double and long double


datatypes.

d. Write a program to enter the values of two variables from the keyboard and
then interchange the values of the two variables. E.g.-
If entered value of x is 5 and y is 10 then
printf("%d %d",x,y )should print 10 5.

 To find Total Mark and Percentage:

Algorithm:

Step 1: Start

Step 2: Declare variable m1,m2,m3,t,p


Step 3:Set m1=78,m2=45,m3=60

Step 4: Set t=m1+m2+m3

Step 5: Set p=(t/300)*100

Step 6: Display t and p

Step 7: stop

Flowchart:

Program:

#include<stdio.h>

#include<conio.h>

void main()

float m1=78,m2=45,m3=62,t,p;

clrscr();

t=m1+m2+m3;

p=(t/300)*100;

printf(“Total Mark of Robert : %f”,t);

printf(“\nPersentage : %f”,p);

getch();

Output:
 To find Size of given data types:

Algorithm:

Step 1: Start

Step 2: Display Sizeofint

Step 3: Display Sizeof char

Step 4: Display Sizeof float

Step 5: Display Sizeofdouble

Step 6: Display Sizeof long double

Step 7: stop

Flowchart:

Program:

#include<stdio.h>

#include<conio.h>

void main()

clrscr()

printf(“Size of Int: %d”,sizeof(int));


printf(“\nSize of Char : %d”,sizeof(char));

printf(“\nSize of Float : %d”,sizeof(float));

printf(“\nSize of Double : %d”,sizeof(double));

printf(“\nSize of Long Double : %d”,sizeof(long double));

getch();

Output:

 To Interchange two values:

Algorithm:

Step 1: Start

Step 2: Declare variable a,b

Step 3: Get value of a and b

Step 4: Set a=a+b

Step 5: Set b=a-b

Step 6: Set a=a-b


Step 7: Display a and b

Step 8: Stop

Flowchart:

Program:

#include<stdio.h>

#include<conio.h>

void main()
{

inta,b;

clrscr();

printf(“Enter value of A : “);

scanf(“%d”,&a);

printf(“Enter value of B : “);

scanf (“%d”,&b);

a=b+a;

b=a-b;

a=a-b;

printf(“After SwapingValueOf A = %d and B = %d”,a,b);

getch();

Output:
Ex.No:2
Decision and Looping Statements
Date:22.12.2020

Aim:
To develop C programs to implement decision making and looping statements.

Problem Statement(s) & Test case

Programs using decision and looping statements

a. C program to check whether the entered year is leap year or not using if..else

Algorithm:
Step1: Start
Step2: Delclare variable y
Step3:Get value of y
Step 4: if y%4==0 and y%100!=0 or y%400%==0 then print leap year
Step5: else then print not a leap year
Step6: Stop
Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int y;
clrscr();
printf("Enter the year : ");
scanf("%d",&y);
if((y%4==0) && ((y%100!=0) || (y%400==0)))
{
printf("Year %d is Leap Year",y);
}
else
{
printf("Year %d is not Leap Year",y);
}
getch();
}

Output:

b. C program to get 4 numbers as input and find the largest among the 4 numbers using
if..else if ladder

Algorithm:
Step1: Start
Step2: Declare variable a,b,c,d
Step3: Get value of a,b,c,d
Step4: if (a>=b and a>=c and a>=d) then print a is largest
Step5: else if (b>=a and b>=c and b>=d) then print b is largest
Step6: else if (c>=a and c>=b and c>=d) then print c is largest
Step7: else then print d is largest
Step8: Stop

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf("Enter 1st Value : ");
scanf("%d",&a);
printf("Enter 2nd Value : ");
scanf("%d",&b);
printf("Enter 3rd Value : ");
scanf("%d",&c);
printf("Enter 4th Value : ");
scanf("%d",&d);
if(a>=b && a>=c && a>=d)
{
printf("The largest among the 4 numbers = %d",a);
}
else if(b>=a && b>=c && b>=d)
{
printf("The largest among the 4 numbers = %d",b);
}
else if(c>=a && c>=b && c>=d)
{
printf("The largest among the 4 numbers = %d",c);
}
else
{
printf("The largest among the 4 numbers = %d",d);
}
getch();
}

Output:

c. Using Switch statement, write a C program that displays the following menu
for the food items available to take order from the customer:
• B= Burger
• F= French Fries
• P= Pizza
• S= Sandwiches
The program inputs the type of food and quantity. It finally displays the
total charges for the order according to following criteria:
• Burger = Rs. 200
• French Fries= Rs. 50
• Pizza= Rs. 500
• Sandwiches= Rs. 150

Algorithm:
Step1: Start
Step2: Declare variable c,q
Step3: Display food items available
Step4: Get food item code in c
Step5: Get amount of quantity required in q
Step6: Display total amount of order by switch statement
Step7: Display Thankyou For Your Order
Step8: Stop

Program:

#include<stdio.h>
#nclude<conio.h>
void main()
{
char c;
int q;
clrscr();
printf("Foods Items Available\n");
printf("1.Burger(B)\n");
printf("2.French Fries(F)\n");
printf("3.Pizza(P)\n");
printf("4.Sandwiches(S)\n");
printf("Enter your order item code : ");
scanf("%c",&c);
printf("Enter no of quantity required : ");
scanf("%d",&q);
switch(c)
{
case 'B':
{ printf("\nTotal amount for your order : %d",(200*q));
break;}
case 'F':
printf("\nTotal amount for your order : %d",(50*q));
break;
case 'P':
printf("\nTotal amount for your order : %d",(500*q));
break;
case 'S':
printf("\nTotal amount for your order : %d",(150*q));
break;
default:
printf("\nInvalied Choice");
}
printf("\nThanks For Your Order");
getch();
}

Output:

1.To display the Fibonacci series

Algorithm:

Step1:Start
Step2:Declare variable a=0,b=1,c,n
Step3:Get n value
Step4:Run the loop till n-2
Step5:Set c=a+b
Step6:Display c
Step7: Set a=b,b=c

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a=0,b=1,c;
clrscr();
printf("Enter Limit of Fibonacci Series : ");
scanf("%d",&n);
printf("\n%d\n%d",a,b);
for(i=0;i<(n-2);i++)
{
c=a+b;
printf("\n%d",c);
a=b;
b=c;
}
getch();
}

Output:

2. Write a program in C to display the pattern like right angle triangle using an
asterisk.
*
**
***
****

Algorithm:

Step1:Start
Step2:Declare variable i=1,j=1
Step3:Run outer loop untill i<5
Step4:Run inner loop until j<=i
Step5:display *
Step6:stop
Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
getch();
}

Output:

3. Write a program in C to display the pattern like right angle triangle with a
number.
1
12
123
1234

Algorithm:

Step1:Start
Step2:Declare variable i=1,j=1
Step3:Run outer loop untill i<5
Step4:Run inner loop until j<=i
Step5:display j
Step6:Stop

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
getch();
}

Output:
Ex.No:3
Arrays and Strings
Date:19.1.2021

Aim:
To develop C programs to implement arrays and Strings.

Programming using Arrays

a. To search for particular number among N numbers(1D array)

Algorithm:

Step1:Start
Step2:Get N numbers from user and store in a[100] 1d array
Step3:Get the value to be search in variable p
Step4:Compare p with one by one index value of a[n]
Step5:if p=a[i] go to step 6 else go to step 7
Step6:display value found in index i
Step7:else display not found
Step8:End
Program:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[100],n,i,p,f=0;
clrscr();
printf("Enter the Limit : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value of a[%d] : ",i);
scanf("%d",&a[i]);
}
printf("Enter Element to be search : ");
scanf("%d",&p);
for(i=0;i<n;i++)
{
if(p==a[i])
{
printf("The value %d is in index a[%d]",p,i);
f=1;
break;
}
}
if(!f)
{
printf("The value %d is not found",p);
}
getch();
}

Output:
b. To compute matrix addition (2 D array)
Algorithm:

Step1:Start
Step2:Get row size and coloumn size
Step3:Get the first matrix value in a[row][col] and second matrix value in b[row][col]
Step4:for i=0 to row
Step5:for j=0 to col
Step6:Set ans[i][j]=a[row][col]+b[row][col]
Step7:display ans[i][j]
Step8:End

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],row,col,ans[10][10],i,j;
clrscr();
printf("Enter the No Of Row:");
scanf("%d",&row);
printf("Enter the No Of Culomn:");
scanf("%d",&col);
printf("Enter 1st Matrix Values\n");
for( i=0;i<row;i++)
{for( j=0;j<col;j++)
{
printf("Enter [%d][%d] Value:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter 2nd Matrix Value\n");
for(i=0;i<row;i++)
{for(j=0;j<col;j++)
{printf("Enter [%d][%d] Value:",i,j);
scanf("%d",&b[i][j]);
}
}
printf("Addision of two Matrix");
for( i=0;i<row;i++)
{ printf("\n");
for( j=0;j<col;j++)
{
ans[i][j]=a[i][j]+b[i][j];
printf("%d ",ans[i][j]);
}
}
getch();
}

Output:
Ex.No:4
Functions and Strings
Date:

Aim:
To develop C programs to implement Functions and Strings.

Programs using Functions and Strings (any 2)

a. To swap two numbers using call by reference.


Algorithm:
Step1:Get two values in variable a and b
Step2:Send address of two variable to the function swap
Step3: Set *y=*y+*x
Step4:Set *x=*y-*x;
Step5:Set *y=*y-*x;
Step6:Print a and b in main function
Step7:Stop

Program:
#include<stdio.h>
#include<conio.h>
void swap(int *x,int *y);
void main()
{
int a,b;
clrscr();
printf("Enter A and B value:");
scanf("%d %d",&a,&b);
swap(&a,&b);
printf("The Values Swaped A=%d and B=%d",a,b);
getch();
}
void swap(int *x,int *y)
{
*y=*y+*x;
*x=*y-*x;
*y=*y-*x;
}

Output:
b. To find the cube of a number using recursion
Algorithm:
Step1:Start
Step2:Get value in the variable a
Step3:Send value of a to function cube
Step4:Set static i=0
Step5:Set i=i+1
Step6:if i<3 go to step7 else goto step8
Step7:return b*cube(b)
Step8:return b
Step9:Stop

Program:
#include<stdio.h>
#include<conio.h>
int cube(int b);
void main()
{
int a;
clrscr();
printf("Enter integer value : ");
scanf("%d",&a);
printf("Cube value of %d : %d",a,cube(a));
getch();

}
int cube(int b)
{
static int i=0;
i++;
if(i<3)
{
return (b*cube(b));
}
else
{
return b;
}
}

Output:

c. To manipulate strings using string functions

Algorithm:

Step1:Start
Step2:Include string.h header file
Step3:Get 2 strings in variable a and b
Step4:Do string operation using inbuild string functions
Step5:Stop

Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[20];
clrscr();
printf("Enter string1 : ");
gets(a);
printf("Enter string2 : ");
gets(b);
printf("Length of string1 : %d\n",strlen(a));
printf("Copy \"Night\" to string2 : %s\n",strcpy(b,"Night"));
printf("Combine two strings and store in string1 : %s\n",strcat(a,b));
printf("Check string1 and string2 are same : %d\n",strcmp(a,b));
printf("First oocurrence of \"odNi\" in string1 : %s\n",strstr(a,"odNi"));
printf("String1 in upper case : %s\n",strupr(a));
printf("String2 in lower case : %s\n",strlwr(b));
printf("Reverse the string1 : %s\n",strrev(a));
printf("Enter string1 : ");
gets(a);
printf("Enter string2 : ");
gets(b);
printf("Combine 1st 5 character of string2 to string1 : %s\n",strncat(a,b,5));
printf("Copy 1st 5 character of string1 to string2 : %s\n",strncpy(b,a,5));
printf("Compare 1st 5 character of string1 and string2 : %d",strncmp(a,b,5));
getch();
}

Output:

d. To check whether the string is palindrome or not

Algorithm:
Step1:Start
Step2:Get String in variable s
Step3:Set i=0,j=length of s – 1 repeat Step4 till i<=j
Step4:if s[i]==s[j] goto step5 else goto step6
Step5:Set f=0
Step6:Set f=1 goto step 7
Step7:if f=0 print palindrome else goto spep8
Step8:print not palindrome
Step9:Stop

Program:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[50];
int i,j,f;
clrscr();
printf("Enter the string : ");
gets(s);
j=strlen(s)-1;
for(i=0,j;i<=j;i++,j--)
{
if(s[i]==s[j])
{
f=0;
}
else
{
f=1;
break;
}
}
if(f==0)
{
printf("The given string is palindrome");
}
else
{
printf("The given string is not palindrome");
}
getch();
}

Output:

Result:

C programs to process data types, operators and expression


evaluation were implemented and executed. The results were
verified against the test cases.

You might also like