Welcome to our interactive practice sessions dedicated to mastering the C programming language In this blog series, we work on a journey to strengthen our C skills through hands on exercises and practical challenges.
Lets start with what we learned so far
Q1 : Write a program that subtracts the value 15 from 87 and displays the result, together with an appropriate message, at the terminal.
Answer :
#include <stdio.h>
int main() {
int num1 = 87;
int num2 = 15;
int result = num1 - num2;
printf("Subtracting %d from %d gives %d\n", num2, num1, result);
return 0;
}
Q3 : What output might you expect from the following program?
#include <stdio.h>
int main (void){int answer, result;
answer = 100;result = answer - 10;printf ("The result is %i\n", result + 5); return 0;}
Answer : Output is 95
Q3 : What output would you expect from the following program?
#include <stdio.h>
int main (void){char c, d;
c = 'd';
d = c;printf ("d = %c\n", d);
return 0;}
Answer : " d = d "
Q4 : Convert given value in Meter to centimeter.(Write a C program)
Answer :
#include <stdio.h>
int main() {
float meters, centimeters;
/* Taking input values from user */
printf("Enter the value in meters: ");
scanf("%f", &meters);
/* Convert meters to centimeters */
centimeters = meters * 100;
/* Display the result */
printf("%.2f meters is equal to %.2f centimeters\n", meters, centimeters);
return 0;
}
Answer :
#include <stdio.h>
int main() {
float PI = 3.14;
float radius, height, volume;
/* Input values for radius and height */
printf("Enter the radius of the cylinder: ");
scanf("%f", &radius);
printf("Enter the height of the cylinder: ");
scanf("%f", &height);
/* Calculate volume using the equation */
volume = PI * pow(radius, 2) * height;
/* Display the result */
printf("The volume of the cylinder is: %.2f\n", volume);
return 0;
}
Stay tuned for more exciting updates and valuable insights coming your way!
Designer : M.I AFTHAL AHAMAD (ICT/2022/105)
0 Comments