ESC0102P - Profram For Problem Solving Lab File
ESC0102P - Profram For Problem Solving Lab File
:August 2018
Noida International University Form No. Acad. -001
Department of Computer Science & Engineering
1. Write a program to print the cube of any number provided by the user.
2. Make a program to calculate the simple interest for 3 sets of p, n, r using while and for loop.
3. Write a program to print the sum of all the digits from 1 to 10 using while loop.
4. Write a program to print the digit from 1 to100 using while and for loop.
5. Using for loop print the following
pattern R=1 c=1 sum=2
R=1 c=2 sum=3
R=2 c=1 sum
=3 R=2 c=2
sum=4
6. Write a program to print the following pattern
7. Write a program to print the square and cube of any given
number. 8.
***** * 1
***** ** 12
***** *** 123
***** **** 1234
***** 12345
Problems based on 1-D Array, Array Manipulation, 2-D Array and String Operations:
1. Write a program to perform following operations on String(s) using a well-defined library function:
● Find the length of the string.
● Concatenate two strings
● Compare two given strings
● Copy the content of string to another string
2. Write a program to find average marks obtained by a class of 30 students in a test.
3. Write a program to find the maximum marks obtained by a student in 5 subjects.
4. Write a program to pick up the largest number from any 5 row by 5 column matrix.
5. Twenty five numbers are entered from the keyboard into an array. Write a program to find out
how many of them are positive, how many of them are negative and how many of them are
zeros.
6. Write a program to store n elements in an array and print all elements.
7. Write a program to compute the sum of all elements in an array.
8. Write a program to print the elements of an array in reverse order.
1. Write a program to enter name, price and page number of three books using structure.
2. Write a program to enter roll number and average marks of 3 students using structure.
3. Create a structure to specify data of customer in a bank. The data to be stored is: Account
number, Name, Balance in Account. Assume maximum of 200 customers in the bank. Write a
program to print name and account number of each customer with balance below Rs. 100.
4. A record contains name of cricketer, his age, number of test matches that he has played and the
average runs that he has scored. Create an array of structures to hold records of 20 such
cricketers.
5. There is a structure called employee that holds information like employee code, name, and year
of joining. Write a program to create an array of structures and enter some data into it. Then ask
the user to enter current year. Display the names of those employees whose tenure is more than
3 years according to given year.
Problems based on Function, Pointer, Call by Value and Call by Reference
1. Write function which receives a float and an integer from main (), find the product of these two
and returns the product which is printed through main ().
2. Write a function that receives marks received by a student in 3 subjects and returns the average
and percentage of these marks. Call this function from main and print the result in main.
3. Find the smallest number in an array.
4. Any year is entered through the keyboard. Write a function to determine whether the year is a
leap year or not.
5. Write a function that receives 5 integers and returns the sum, average of these numbers. Call
this function from main () and print the result in main ().
6. Write a program to add two numbers using pointers.
7. Write a program to store n elements in an array and print all elements using pointer.
8. Write a program to read array elements and print array addresses using pointer.
9. Write a program to compute the sum of all elements in an array using pointer.
10. Write a program to print the elements of an array in reverse order using pointer.
Problems based on Recursion, recursive functions, file handling operations and numerical method
problems:
Experiment No.1 : If the three sides of the triangle are entered through the keyboard, write a
program to check whether the triangle is isosceles or equilateral.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
scanf("%d%d%d",&side1,&side2,&side3);
");
");
else
");
getch();
}
Experiment No. 2
Following is the C program to check whether the triangle is equilateral, isosceles or scalene –
#include<stdio.h>
int main(){
scanf("%d%d%d",&side1,&side2,&side3);
");
");
else
");
return 0;
}
Experiment No. 3
In a company an employee is paid under: If his basic salary is less then Rs.1500, then HRA=10% of basic
salary and DA=90% of basic salary .If his salary is either equal to or above Rs 1500, then HRA=Rs 500 and DA=
98% of basic salary. If the employee’s salary is input through the keyboard write a program to find his gross
salary.
#include<stdio.h>
int main()
int cy,yj;
scanf("%d %d",&cy,&yj);
if(cy-yj>3)
printf("bonus of Rs 2500/-");
else
printf("program error");
}
Experiment No. 4
Write a program to check whether a triangle is valid or not when the three angles of the triangle are entered
through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180 degree.
#include<stdio.h>
#include<conio.h>
int main()
int a, b, c, sum;
sum = a+b+c;
if (sum == 180)
printf("Triangle is valid");
else
return 0;
}
Experiment No. 5
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 time taken by
the worker is input through the keyboard, write a program to find the efficiency of the worker.
#include<stdio.h>
#include<conio.h>
int main()
float hours;
scanf("%f", &hours);
return(0);
}
Experiment No. 6
Write a program to print the square and cube of any given number
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
float side;
scanf(“%f”,&side);
getch();
}
Experiment No. 7
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
float radius;
scanf(“%f”,&radius);
getch();
}
Experiment No. 8
If cost price and selling price of item is input through the keyboard, write a program to determine
whether the seller gas made profit or incurred loss. Also determine how much profit he made or
loss he incurred.
#include<stdio.h>
#include<conio.h>
void main()
int cp,sp,tl,tp;
scanf("%d",&cp);
scanf("%d",&sp);
if(sp>cp)
tp=sp-cp;
else if (sp<cp)
tl=cp-sp;
else
getch();
}
Experiment No. 9
Write a program to print the square and cube of any given number
#include<stdio.h>
int main()
scanf("%d", &number);
return 0;
}
Experiment No. 10
Make a program to calculate the simple interest for 3 sets of p, n, r using while and for loop.
#include<stdio.h>
#include<conio.h>
void main()
int p,n,count=1;
float r,si;
clrscr();
while(count<=3)
scanf(“%d%d%f”,&p,&n,&r);
si=(p*n*r)/100;
count++;
getch();
#include<stdio.h>
#include<conio.h>
void main()
int p,n,count;
float r,si;
clrscr();
for(count=1;count<=3;count++)
scanf(“%d%d%f”,&p,&n,&r);
si=p*n*r/100;
printf(“Simple Interest=%f”,si);
getch();
}
Experiment No. 12
Write a program to print the sum of all the digits from 1 to 10 using while loop.
#include <stdio.h>
int main(){
/* Declare variable i. */
int i;
printf("%d ",i);
return 0;
}
Experiment No. 13
#include <stdio.h>
int main() {
int n, i, sum = 0;
scanf("%d", &n);
sum += i;
return 0;
}
Experiment No. 14
#include <stdio.h>
int main()
int rows = 5;
printf("* ");
printf("\n");
return 0;
}
Experiment No. 15
Write a program to print the square and cube of any given number.
#include<stdio.h>
#include<conio.h>
void main()
int a,s,c;
clrscr();
scanf("%d",&a);
getch();
}
Experiment No. 16
12
123
1234
12345
#include <stdio.h>
int main()
int i, j, n;
scanf ("%d",&n);
for(i=1;i<=n;i++)
for (j=1;j<=i;j++)
printf ("%d",j);
printf ("\n");
}
Experiment No. 17
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
float side;
scanf(“%f”,&side);
getch();
}
Experiment No. 18
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
float side;
scanf(“%f”,&side);
getch();
}
Experiment No. 19
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
float radius;
scanf(“%f”,&radius);
getch();
}
Experiment No. 20
#include <stdio.h>
int main() {
int i = 1;
do {
printf("%d\n", i);
i++;
return 0;
}
Experiment No. 21
#include <stdio.h>
int main() {
int i;
printf("%d\n", i);
return 0;
}
Experiment No. 22
***** * 1
***** ** 12
***** *** 123
***** **** 1234
***** 12345
#include <stdio.h>
int main()
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
printf("* ");
printf("\n");
return 0;
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
printf(" ");
for(int k=1;k<=n;k++)
printf("*");
printf("\n");
return 0;
}
Experiment No. 23
#include<stdio.h>
#include<conio.h>
void main()
{
Int sum =0;
for(int i=1;i<=50;i++)
{
Sum +=I;
}
printf(“Sum is %d”,sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
Int a,b,sum=0;
Printf(“Enter the first number:”);
Scanf(%d”, &a);
Printf(“Enter the second number:”);
Scanf(%d”, &b);
Sum=a+b;
Printf(“Sum is %d”,sum);
getch();
}
#include<stdio.h>
#include<math.h>
float squareArea(float side);
float circleArea(float rad);
float rectangleArea(float a, float b);
int main()
{
float a=5.0;
float b=10.0;
printf(“area is :%f”, rectangleArea(a,b));
return 0;
}
float squareArea(float side)
{
return side*side;
}
float circleArea(float rad)
{
return 3.14*rad*rad;
}
float rectangleArea(float a, float b)
{
return a*b;
}
Result:- We have successfully compiled the program
area is :50.000000
Experiment No. 26
Program:
/**
* C program to print all natural numbers from 1 to n
*/
#include <stdio.h>
int main()
{
int i, n;
/*
* Start loop counter from 1 (i=1) and go till n (i<=n)
* increment the loop count by 1 to get the next value.
* For each repetition print the value of i.
*/
for(i=1; i<=n; i++)
{
printf("%d\n", i);
}
return 0;
}
Experiment No. 27
Program:
/**
* C program to check whether a student is pass or fail
*/
#include <stdio.h>
int main() {
int marks;
printf("enter marks(0-100) \n");
scanf("%d", &marks );
if (marks <= 30){
printf ("fail\n");
printf("Better Luck Next Time");
}
else if ( marks >30 && marks <= 100)
{ printf(" pass");
printf("\nWell done!");
}
else { printf(" wrong marks");
}
return 0;
}
enter marks(0-100)
67
pass
Well done!
Experiment No. 28
Program:
/**
* C program to find the factorial of n and n is given
*/
int main()
return 0;
int fact(int n)
if(n==0)
return 1;
else
return n*fact(n-1);
}
Experiment No. 29
Write a C program to find the given number is either positive or negative (even and odd)
Resources: PC, Power, Compiler
Program:
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if(num>=0)
printf("Positive \n");
if(num % 2 == 0)
else
return 0;
Enter an integer: 45
Positive
45 is odd.
Experiment No. 30
Program:
/**
* C program to to convert celcius to farhenheit.
*/
#include <stdio.h>
float convertCelFahrenheit(float c)
int main()
scanf("%f", &celsius);
fahrenheit = convertCelFahrenheit(celsius);
return 0;
}
Experiment No. 31
Program:
/**
* C program to check whether a student is fail or pass.
*/
#include <stdio.h>
int main(void) {
int marks;
scanf("%d",&Marks);
printf("\nResult is pass");
else
printf("\nResult is fail");
return 0;
}
Experiment No. 32
Program:
/**
* C program to print the table of a number input by user.
.
*/
#include <stdio.h>
int main()
scanf (" %d", &num); // take a positive number from the user
return 0;
}
Experiment No. 33
Program:
/**
* C program using call by value function
.
*/
#include <stdio.h>
int main()
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b); // printing the value of a and b in main
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b); // The value of actual parameters do not change by c
hanging the formal parameters in call by value, a = 10, b = 20
int temp;
temp = a;
a=b;
b=temp;
}
Experiment No. 34
Program:
/**
* C program to make pattern of triangle
.
*/
Include<stdio.h>
int main()
Int n,I,j;
scanf(“%d”,&n);
for(i=1;i<=n;i++)
printf(“”);
for(j=1;j<=I;j++)
printf(“*”);
printf(“\n”);
‘return 0;
Problems based on 1-D Array, Array Manipulation, 2-D Array and String Operations:
Experiment No. 35
Write a program to perform following operations on String(s) using a well-defined library function:
● Find the length of the string.
● Concatenate two strings
● Compare two given strings
● Copy the content of string to another string
#include <stdio.h>
int main() {
int i;
return 0;
#include <stdio.h>
int main() {
int length, j;
length = 0;
++length;
}
// concatenate s2 to s1
s1[length] = s2[j];
s1[length] = '\0';
puts(s1);
return 0;
#include<stdio.h>
int main()
char name[10];
double mob_no;
printf("Name: ");
gets(name);
printf("Date: ");
scanf("%d", &date);
printf("Month: ");
scanf("%d", &month);
printf("Year: ");
scanf("%d", &year);
printf("Mob_no: ");
scanf("%lf", &mob_no);
printf("Hi %s!! \nYour DOB is %d/%d/%d and mobile number is %lf", name, date, month, year, mob_no);
return 0;