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

Practical File From 1 To 10

The document contains 10 programming problems to solve in C language. It provides the problem statements, objectives and sample code for each problem. The problems cover basic concepts like arithmetic operations, conditional statements, loops, arrays, functions, pointers and structures.

Uploaded by

neonboy88855
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)
50 views

Practical File From 1 To 10

The document contains 10 programming problems to solve in C language. It provides the problem statements, objectives and sample code for each problem. The problems cover basic concepts like arithmetic operations, conditional statements, loops, arrays, functions, pointers and structures.

Uploaded by

neonboy88855
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/ 13

Practical File

Subject : Programming with C for Problem Solving

Submitted By : Submitted To :
Mr.M Siva Rama Krishna Mr.Rahul Dev
Singh
B.Tech CSE(AI&ML) Dept.Of CSE
Semister/Year :II/1 SOEIT , Sanskriti
University
Enrollment Number:2302320164

1
Sr.No. PROBLEM STATEMENT Page Teacher’s
no. Remarks
1 Write a Program to calculate and display the 03
volume of a CUBE having its height (h=10cm),
width (w=12cm) and depth (d=8cm).
2 Write a program to take input of name, roll no 04
and marks obtained by a student in 4 subjects of
100 marks each and display the name, roll no
with percentage score secured.

3 Write a program to print whether a given number 05


is even or odd.
4 Write a program to print positive integers from 1 06
to 10.

5 Write a program to insert 5 elements into an array 07


and print the elements of the array.
6 Write a C program to add two matrices A and B 08
of size 3x3 and store the result in matrix C.

7 Write a program to calculate factorial of a 09


number using recursion.
8 Write a C program to create, declare and initialize 10
structure.

9 Check whether the given string is a palindrome or 11


not.
10 Write a program to find the biggest among three 12
numbers using pointer.

Index :

2
Practical-01
Objective: Write a Program to calculate and display the volume of a CUBE having its height
(h=10cm), width (w=12cm) and depth (d=8cm).

Programme:

#include <stdio.h>

int main() {
int h=10,w=12,d=8;
int v;
v=h*w*d;
printf("The volume of a cube =%d ",v);
return 0;
}

Output:

3
Practical-02
Objective: Write a program to take input of name, roll no and marks obtained by a student in 4
subjects of 100 marks each and display the name, roll no with percentage score secured.

Programme:

#include <stdio.h>

int main() {
int roll,s1,s2,s3,s4;
float sum=0,avg=0;
char name;
printf("enter the name of a student : ");
scanf("%s",&name);
printf("enter the roll number of a student : ");
scanf("%d",&roll );
printf("enter the s1 marks : ");
scanf("%d",&s1);
printf("enter the s2 marks : ");
scanf("%d",&s2);
printf("enter the s3 marks : ");
scanf("%d",&s3);
printf("enter the s4 marks : ");
scanf("%d",&s4);
sum=s1+s2+s3+s4;
avg=sum/4;

printf("the percentage got by a student =%f ",avg );

return 0;
}

Output:

4
5
Practical-03
Objective: Write a program to print whether a given number is even or odd.

Programme:

#include <stdio.h>

int main() {
int a,n;
printf("enter the number n : ");
scanf("%d",&n);
if(n%2==0)
{
printf("it is a even number ");

}
else {
printf("it is a odd number ");
}
return 0;
}

Output:

6
Practical-04
Objective: Write a program to print positive integers from 1 to 10.

Programme:

#include <stdio.h>

int main() {
int i;
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}
return 0;
}

Output:

7
Practical-05
Objective: Write a program to insert 5 elements into an array and print the elements of the

array.

Programme:

#include <stdio.h>

int main() {
int a[5];
int i;
printf("enter the elements of an array :");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("%d\n",a[i]);
}
Return 0;
}
Output:

8
Practical-06
Objective: Write a C program to add two matrices A and B of size 3x3 and store the
result in matrix C.

Programme:

#include<stdio.h>
int main() {
int a[3][3],b[3][3],c[3][3];
int i,j,k;
printf("enter the elements of first matrice ");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of second matrice ");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
}
printf(" the addition of matix is \n: ");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++){
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);}
}
return 0;
}
Output:

9
Practical-07
Objective: Write a program to calculate factorial of a number using recursion.

Program:

#include<stdio.h>
//printing factorial using recursion function
int factorial(int n)
{
if(n<=1)
return 1;
else
return n *(factorial(n-1));
}
void main()
{
int n;
printf("enter the value of n :");
scanf("%d",&n);
printf("The factorial of a number is=%d",factorial( n));

Output:

10
Practical-08
Objective:Write a C program to create, declare and initialize structure.

Program:

#include <stdio.h>
struct biodata {
char name[1000];
int age;
float height;
} abc ;

void main() {
printf("biodata of a person :\n");
printf("enter the name of person :\n",&abc.name );
scanf("%s",&abc.name );

printf("enter the age \n :",abc.age );


scanf("%d", &abc.age);
printf("enter the height :",abc.height );
scanf("%f", &abc.height);

}
Output:

11
Practical-09
Objective:Check whether the given string is a palindrome or not.

Program:

#include<stdio.h>
#include<string.h>
int palindrome(char str[])
{
int i=0;
int j=strlen(str)-1;
while(i<j)
{
if(str[i] !=str[j])
{
return 0;
}
i++;
j--;
}
return 1;
}
void main()
{
char str[100];
printf("enter the string ");
scanf("%s",&str);
if(palindrome(str))
{
printf("%s is a palindrome ",str);
}
else {
printf("%s is not a palindrome ",str);
}
}
Output:

12
Practical-10

Objective: Write a program to find the biggest among three numbers


using pointer.

Programme:
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the values :");
scanf("%d%d%d",&a,&b,&c);
int *p1=&a;
int *p2=&b;
int *p3=&c;
int s=*p1;
if(*p2>s)
{ s=*p2; }
if(*p3>s)
{ s=*p3; }
printf("the biggest among thrre numbers is=%d",s);
return 0;
}
Output:

13

You might also like