0% found this document useful (0 votes)
31 views14 pages

Cfile

C file chitkaraUniversity completed

Uploaded by

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

Cfile

C file chitkaraUniversity completed

Uploaded by

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

Practical File

of
Fundamentals of C
22CS002
Submitted

in partial fulfillment for the award of the degree

of

BACHELOROFENGINEERING
in

COMPUTER SCIENCE & ENGINEERING

CHITKARA UNIVERSITY

CHANDIGARH-PATIALA NATIONAL HIGHWAY


RAJPURA (PATIALA) PUNJAB-140401 (INDIA)
January, 2024

Submitted To: Submitted By:

Faculty name: Dr. Gaganpreet kaur Name:Kabir


Designation: Associate Professor Roll No2310990705
Chitkara University, Punjab Sem:2

Fundamentals of C Programming -22CS002


Fundamentals of C Programming -22CS002

INDEX
Sr. Practical Name Teacher Sign
No.
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/2at 2 (iii) T=2*a+√b+9c (iv) H=√b 2 +p 2

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:

1. Conditional Operator
2. If-Else statement

8 Write the following programs using switch case statement:


1. To check that an input alphabet is vowel or consonant
2. To check whether a number is positive, negative or zero

Fundamentals of C Programming -22CS002 Page2


Fundamentals of C Programming -22CS002
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 a;
printf("Please enter value of a:\n");
scanf("%d",&a);
printf("The value of a is: %d",a);
}

Output:

Fundamentals of C Programming -22CS002 Page3


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

Solution:

#include<stdio.h>
int main()
{ int b=23;
int k=78;
printf("The sum of %d and %d is: %d",b,k,b+k);
}

Output:

Fundamentals of C Programming -22CS002 Page4


Fundamentals of C Programming -22CS002
Output:

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("Please enter the value of radius:\n");
scanf("%d",&r); float a=(3.14*r)*r; float
c=(2*3.14)*r;
printf("Area of circle is: %.2f\n",a);
printf("Circumference of circle is: %.2f",c);
}

Output:

Fundamentals of C Programming -22CS002 Page5


Fundamentals of C Programming -22CS002

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 a;
int b;
printf("Please enter value of a and b\n");
scanf("%d %d",&a,&b);
printf("The sum of %d and %d is: %d\n",a,b,a+b);
printf("The difference of %d and %d is: %d\n",a,b,a-b);
printf("The product of %d and %d is: %d\n",a,b,a*b);
printf("The division of %d and %d is: %d\n",a,b,a/b);
}

Output:

Fundamentals of C Programming -22CS002 Page6


Program 5:Write a program to evaluate each of the following equations.
(i) V = u + at. (ii) S = ut+1/2at 2 (iii) T=2*a+√b+9c (iv) H=√b 2 +p 2

Solution:

#include <stdio.h>
int main(){
int u,v,a,t,s;
printf("Please enter the value of u,a,t:");
scanf("%d %d %d",&u,&a,&t);
printf("v=u+at\n");
printf("v=%d\n",u+(a*t));
printf("s=ut+1/2at^2\n");
printf("s=%d",u*t+(1/2*a*(t*t)));

int T,A,b,c;
double d=sqrt(b);
printf("Please enter the value of A,b,c:");
scanf("%d %d %d",&A,&b,&c);
printf("T=2*A+d+9c\n");
printf("T=%lf",2*(A+(d+9*c)));

int H,p,b;
printf("Please enter value of b and p:\n");
scanf("%d %d",&b,&p);
printf("H=%d",b+(p*p));
}

Output:

Fundamentals of C Programming -22CS002 Page7


Fundamentals of C Programming -22CS002

Fundamentals of C Programming -22CS002 Page8


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

Solution:
a)
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter numbers to swap: ");
scanf "%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("a: %d , b: %d", a, b);
return 0;
}

Output :

Fundamentals of C Programming -22CS002 Page9


Fundamentals of C Programming -22CS002
printf("Enter t

B)

Solution:

#include <stdio.h>
int main() {
int a , b;
printf("Enter number to swap: ");
scanf("%d %d" ,&a, &b);
printf("a: %d , b: %d",b , a);
return 0; }

Output:

Fundamentals of C Programming -22CS002 Page10


Fundamentals of C Programming -22CS002
b)

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

1.Conditional Operator
2.If-Else statement
Solution: a)
#include<stdio.h>
int main()
{
int a, b, c ; printf("Please enter value of a, b
and c: ");
scanf("%d %d %d", &a, &b, &c);
Conditional operator
int Largest=(a>b && a>c? a:b>c? b:c);
printf("The largest number is: %d",Largest);
}

b)
#include<stdio.h>
int main()
{
int a, b, c ;
printf("Please enter value of a, b and c: ");
scanf("%d %d %d", &a, &b, &c);

Fundamentals of C Programming -22CS002 Page11


Fundamentals of C Programming -22CS002

if(a>b && a>c){ printf("a is


greater");
}
if(b>c && b>a){
printf("b is greater");
}
else{
printf("c is greater");
}
}

Output:

a)

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

Solution:

#include <stdio.h>

int main() {
char ch;

printf("Enter an alphabet: ");


scanf("%c", &ch);
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c is a vowel.\n", ch);
break;
default:
if (isalpha(ch)) {
printf("%c is a consonant.\n", ch);
} else {
printf("%c is not an alphabet.\n", ch);
}
break;
}

return 0;
}

Output:

You might also like