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

Assignment 00

This document contains the responses to 10 programming assignments for a C programming lab. It includes code snippets and output for problems involving Linux commands, simple C programs to print text and perform math operations, variable scope, and converting between Fahrenheit and Celsius temperatures. The document contains identifying information for the student, Taha Zulfiquar, including their roll number, enrollment number, name of the institution and course details.

Uploaded by

tahazulfiquar53
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Assignment 00

This document contains the responses to 10 programming assignments for a C programming lab. It includes code snippets and output for problems involving Linux commands, simple C programs to print text and perform math operations, variable scope, and converting between Fahrenheit and Celsius temperatures. The document contains identifying information for the student, Taha Zulfiquar, including their roll number, enrollment number, name of the institution and course details.

Uploaded by

tahazulfiquar53
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Taha Zulfiquar

Roll no.- 23F029


Enrollment No.- 0801EE231103

Shri G. S. Institute of Technology & Science, Indore


Department of Information Technology
B.Tech (1st Year)
(Jan-June)
CO10507: PROGRAMMING FOR PROBLEM SOLVING
Lab Assignment 00

Q.1 Hands-on the Linux Commands (cd, cmp, cat, Is, man, mkdir, rmdir, mv,
passwd, pwd, rm).
Ans.
Commands Use

cd Change Directory
cmp File Comparision
cat File data elaboration
ls Listing
man Manual (discription of any folder)
mkdir Make directory
mv Move file
passwd Password change
pwd Present working directory
rm Remove file
rmdir Remove directory
cp Copy file
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Q.2 Hands-on the Editing tools (vi/gedit).


Ans. Gedit is an easy-to-use and general-purpose text editor. Its development
started in 1998, at the beginnings of the GNOME project, with a good integration
with that desktop environment.

You can use it to write simple notes and documents, or you can enable more
advanced features that are useful for software development.

It is released under Free/Libre Open Source software licenses.

Q.3 Write a simple C program to print "Hello World".

Code:

#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}

Output:
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Q.4 Write a C program to perform addition, subtraction, multiplication, and


division on two integer variables, "x" and "y" (Take input from the user using
'scanf' function).

Code:

#include <stdio.h>
int main()
{
float a, b, c;
printf("Enter value of a:\n");
scanf("%f", &a);
printf("Enter value of b:\n");
scanf("%f", &b);

// add two numbers


c = a + b;
printf("The sum of a and b is %0.01f.\n", c);

// subtract two numbers


c = a - b;
printf("The subtraction of a and b is %0.01f.\n", c);

// Multiply two numbers


c = a * b;
printf("The product of a and b is %0.01f.\n", c);

// Divide two numbers


c = a / b;
printf("The quotient of a and b is %0.01f.\n", c);
return 0;
}
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Output:

Q.5 Declare three variables, "num1," "num2," and "num3." Calculate the
average of these three numbers and display the result.

Code:

#include <stdio.h>
int main()
{
float num1, num2, num3, avg;
printf("Enter 3 numbers: ");
scanf("%f %f %f", &num1, &num2, &num3);
avg = (num1 + num2 + num3) / 3;
printf("The average of the given numbers is %0.01f.\n", avg);
return 0;
}

Output:
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Q.6 Define a constant named "PI" with a value of 3.14 and calculate the area
of a circle using a radius stored in a variable named "radius."

Code:

#include <stdio.h>
float PI = 3.14;
int main()
{
float radius, area;
printf("Enter the radius: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("The are of the circle with radius %0.1f is %0.1f.",
radius, area);
}

Output:
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Q.7 Write a C program to swap the values of two variables with and without
using a dummy variable.
Code:

#include <stdio.h>
void withdummyvariable(int a, int b, int swap)
{
printf("Before swapping: a = %d, b = %d\n", a, b);
swap = a;
a = b;
b = swap;
printf("After swapping: a = %d, b = %d\n", a, b);
}
void withoutdummyvariable(int a, int b)
{
printf("Before swapping: a = %d, b = %d\n", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("After swapping: a = %d, b = %d\n", a, b);
}
int main()
{
int a, b, swap;
printf("Enter the value of a: ");
scanf("%d", &a);
printf("Enter the value of b: ");
scanf("%d", &b);
printf("\n");

printf("Using a dummy variable:\n");


withdummyvariable(a, b, swap);
printf("\n");

printf("Without using a dummy variable:\n");


withoutdummyvariable(a, b);
return 0;
}
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Output:

Q.8 Declare a global variable "globalVar" with an initial value. Then, declare
a local variable with the same name within a function and print both values to
observe the scope.

Code:

#include <stdio.h>
int globalVar = 29;
void func(int globalVar)
{
/* this stores a temporary value for the variable named globalVar
which can only be accessed when this function is called */
globalVar = 47;
printf("This is a local variable: %d\n", globalVar);
}
int main()
{
printf("This is a global variable: %d\n", globalVar);
int c;
func(c);
return 0;
}
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Output:

Q.10 Write a C program to find Fahrenheit to Celsius and vice versa.


Code:

#include <stdio.h>
int main()
{
float a, b, c;
int num;
printf("Enter 1 to convert Farenheit to Celsius and 2 to convert
Celsius to Fahrenheit: \n");
scanf("%d", &num);
switch (num)
{
case 1:
printf("Enter temperature in fahrenheit: \n");
scanf("%f", &a);
c = (a - 32) * 5 / 9;
printf("The temperature in celsius= %0.01f°\n", c);
break;
case 2:
printf("Enter temperature in celsius: \n");
scanf("%f", &a);
c = (a * 9 / 5) + 32;
printf("The temperature in fahrenheit= %0.01f°\n", c);
break;
default:
break;
}
return 0;
}
Taha Zulfiquar
Roll no.- 23F029
Enrollment No.- 0801EE231103

Output:

You might also like