0% found this document useful (0 votes)
12 views20 pages

LuvBhatia 2310990477 G6

The document contains solutions to 8 programming problems in C language. It demonstrates various concepts like input/output, arithmetic operations, conditional statements, loops etc. Detailed code solutions and outputs are provided for each problem to solve it.

Uploaded by

ms6836320
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)
12 views20 pages

LuvBhatia 2310990477 G6

The document contains solutions to 8 programming problems in C language. It demonstrates various concepts like input/output, arithmetic operations, conditional statements, loops etc. Detailed code solutions and outputs are provided for each problem to solve it.

Uploaded by

ms6836320
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/ 20

Problem Solving using C Programming (23CS003)

Practical File
Of
Problem Solving using
C Programming
23CS003
Submitted
in partial fulfillment for the award of the degree

of

BACHELEOR OF ENGINEERING
in

COMPUTER SCIENCE & ENGINEERING

CHITKARA UNIVERSITY

CHANDIGARH-PATIALA NATIONAL HIGHWAY


RAJPURA (PATIALA) PUNJAB-140401 (INDIA)

June, 2023

Submitted To: Submitted By:

Dr.Preeti Sharma Name: Luv Bhatia


Assistant Professor Roll No. 2310990477
Problem Solving using C Programming (23CS003) Page 1
Problem Solving using C Programming (23CS003)

Chitkara University, Punjab Sem 2, Batch 2023

INDEX

S.No Practical Teacher


Sign
1. Write a Program to show the use to input (Scanf)/output (Printf) statements
and block structure of C-program by highlighting the features of "stdio.h".

2. Write a program to add two numbers and display the sum.

3. Write a program to calculate the area and the circumference of a circle by


using radius as the input provided by the user.

4. Write a Program to perform addition, subtraction, division and multiplication


of two numbers given as input by the user.

5. Write a program to evaluate each of the following equations.


(i) V = u + at. (ii) S = ut+1/2at2 (iii) T=2*a+√b+9c (iv) H=√b2+p2

6. Write a program to swap two variable: a) By using temporary


variable.
b) Without using temporary variable

7. Write a Program to find the greatest among three numbers using: •


Conditional Operator
• If-Else statement

Problem Solving using C Programming (23CS003) Page 2


Problem Solving using C Programming (23CS003)

8. Write the following programs using switch case statement:

• To check that an input alphabet is vowel or consonant

• To check whether a number is positive, negative or zero

Program 1:
Write a Program to show the use to input (Scanf)/output (Printf)
statements and block structure of C-program by highlighting the features
of "stdio.h

Solution:
#include <stdio.h>

int main()
{ int x;
scanf("%d",&x);
printf("the number that you entered is: %d",x);
}

Output:

Problem Solving using C Programming (23CS003) Page 3


Problem Solving using C Programming (23CS003)

Program 2:
Write a program to add two numbers and display the sum.

Solution:

int main()
{ int x,y;
printf("enter the numbers");
scanf("%d %d",&x,&y); printf("%d
+ %d = %d",x,y,x+y);
}

Output:

Problem Solving using C Programming (23CS003) Page 4


Problem Solving using C Programming (23CS003)

Program 3:
Write a program to calculate the area and the circumference of a circle
by using radius as the input provided by the user

Solution:

#include <stdio.h>

int main(){
int r;
printf("enter the radius of the circle: ");
scanf("%d",&r); int cir=2*(22/7)*r; int
area=(22/7)*(r*r); printf("the area of the circle is:
%d\n",area); printf("the circumference of the
circle is: %d",cir);
}

Problem Solving using C Programming (23CS003) Page 5


Problem Solving using C Programming (23CS003)

Output:

Program 4:
Write a Program to perform addition, subtraction, division and
multiplication of two numbers given as input by the user.

Solution:

#include <stdio.h>

int main(){
int x;
int y;
printf("enter the first number: ");
scanf("%d",&x);
printf("enter the second number: ");
scanf("%d",&y); printf("%d + %d
= %d\n",x,x,x+y); printf("%d * %d
= %d\n",x,y,x*y); printf("%d / %d

Problem Solving using C Programming (23CS003) Page 6


Problem Solving using C Programming (23CS003)

= %d\n",x,y,x/y); printf("%d - %d
= %d",x,y,x-y);
}

Output:

Program 5a:
Write a program to evaluate each of the following equations.
V = u + at.

Solution:
#include <stdio.h>

int main(){ int u=0;


int a=0; int t=0;
printf("enter u,a,t: ");

Problem Solving using C Programming (23CS003) Page 7


Problem Solving using C Programming (23CS003)

scanf("%d %d %d",&u,&a,&t);
int v=u+(a*t);
printf("%d=%d+(%d*%d)",v,u,a,t);
}

Output:

Problem Solving using C Programming (23CS003) Page 8


Problem Solving using C Programming (23CS003)

Write a program to evaluate each of the following equations.

Program 5b:

S = ut+1/2at^2

Solution :
#include <stdio.h>

int main()
{ int u,t,a;
printf("enter u,a,t: ");
scanf("%d %d %d",&u,&a,&t);
int s=(u*t)+(1/2*a*t*t);
printf("%d=%d*%d + 1/2*%d*%d^2",s,u,t,a,t);

Output :

Problem Solving using C Programming (23CS003) Page 9


Problem Solving using C Programming (23CS003)

Write a program to evaluate each of the following equations.

Program 5c:

T=2*a+√b+9c

Solution:
#include <stdio.h>
#include <math.h>

int main(){ int a,b,c;


printf("enter a,b,c: ");
scanf("%d %d %d",&a,&b,&c);
int T=(2*a)+sqrt(b)+(9*c);
printf("%d = 2*%d + %d^(1/2) + 9*%d",T,a,b,c);
}

Output:

Problem Solving using C Programming (23CS003) Page 10


Problem Solving using C Programming (23CS003)

Write a program to evaluate each of the following equations.

Program 5d:

d. H=(p^2 + b^2)^(1/2)

Solution :
#include <stdio.h>
#include <math.h>
int main(){ int
b,p;
printf("enter p,b: ");
scanf("%d %d",&p,&b);
int h=sqrt((b*b)+(p*p));
printf("%d = (%d^2 + %d^2)^(1/2)",h,b,p);
}

Output:

Problem Solving using C Programming (23CS003) Page 11


Problem Solving using C Programming (23CS003)

Write a program to evaluate each of the following equations.

Problem Solving using C Programming (23CS003) Page 12


Problem Solving using C Programming (23CS003)

Program 6a:
Write a program to swap two variable: a)
By using temporary variable

Solution : #include
<stdio.h> int
main(){
int a;
int b;
int t;
scanf("%d %d",&a,&b);
t=a;
a=b;
b=t;
printf("a is %d\nb is %d",a,b);
}

Output:

Problem Solving using C Programming (23CS003) Page 13


Problem Solving using C Programming (23CS003)

Program 6b:
Write a program to swap two variable: b)
without using temp

Solution : #include
<stdio.h> int
main(){
int a,b;
scanf("%d %d",&a,&b);
a=a+b; b=a-b; a=a-b;
printf("a is %d\nb in %d",a,b);
}

Output:

Problem Solving using C Programming (23CS003) Page 14


Problem Solving using C Programming (23CS003)

Program 7a:
Write a Program to find the greatest among three numbers using:
a) Conditional Operator

Solution :
#include <stdio.h>
int main(){ int
a,b,c;
scanf("%d %d %d",&a,&b,&c);
int r; r=(a>b)?(a>c?a:c):(b>c?
b:c);
printf("the greatest integer is: %d",r);
}

Output :

Problem Solving using C Programming (23CS003) Page 15


Problem Solving using C Programming (23CS003)

Program 7b:
Write a Program to find the greatest among three numbers using:
b) using if-else

Solution:
#include <stdio.h>
int main(){ int
a,b,c;
scanf("%d %d %d",&a,&b,&c);
int r;
if(a>b){
if(a>c){
r=a; }

Problem Solving using C Programming (23CS003) Page 16


Problem Solving using C Programming (23CS003)

else{
r=c;
} }
else{ if(b>
c){ r=b; }
else{
r=c;
}
}
printf("the greatest integer is: %d",r);
}

Output:

Program 8a:
Write the following programs using switch case statement:
a) To check that an input alphabet is vowel or consonant

Solution : #include
<stdio.h> int
main(){
char x;
scanf("%c",&x);
int a=0; switch
(x) { case
'a': a++;
break; case
'e': a++;
break; case 'i':
a++; break;

Problem Solving using C Programming (23CS003) Page 17


Problem Solving using C Programming (23CS003)

case 'o': a++;


break; case
'u': a++;
break; case
'A': a++;
break; case
'E': a++;
break; case 'I':
a++; break;
case 'O': a++;
break; case
'U':
a++;
break;
}
if(a==1){
printf("character is a vowel");
}
else{
printf("character is a consonant");
}
}

Output:

Problem Solving using C Programming (23CS003) Page 18


Problem Solving using C Programming (23CS003)

Program 8b:
Write the following programs using switch case statement:
b) To check whether a number is positive, negative or zero

Solution : #include
<stdio.h>
int main(){
int a;

Problem Solving using C Programming (23CS003) Page 19


Problem Solving using C Programming (23CS003)

scanf("%d",&a); switch(a){
case -100000 ... -1: printf("the
number is negative");
break; case 1 ... 1000000:
printf("the number is positive");
break; default:
printf("the number is 0");
break;
}
}

Output:

Problem Solving using C Programming (23CS003) Page 20

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy