Facebook Experiences Widespread Outages on March 5 2024

ERC First Semester C Programming LAB SHEET NO.1 [To be familiar with C- Programming]

ERC First Semester C Programming LAB SHEET NO.1 [To be familiar with C- Programming]

Questions:

  1. WAP to display hello world.
  2. WAP to display your name, roll number, and address.
  3. WAP to add two integer variables and print sum.
  4. WAP to multiply two integer variables and print the product.
  5. WAP to calculate and display the simple interest.
  6. WAP to calculate the area of the circle.

Complete Lab Sheet 1

Objective(s): To be familiar with different data types, Operators, and Expressions in C.

1. WAP to display hello world.

Algorithm:

Step 1:Start
Step 2:Display Hello World
Step 3:Stop

Flow Chart

C Program: Code

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

Output

Hello World

Discussion and Conclusion

Discussion: The provided C program demonstrates the basic structure and syntax of a program, including the usage of the printf() function to display output.
Conclusion: By running the program, "Hello, World!" is printed on the console, showcasing a common starting point for beginners learning C programming.

WAP to display your name, roll number, and address.

Algorithm

Step 1: Start
Step 2: Assign Name, Roll Number, and Address on Variables.
Step 3: Display Name, Roll Number, and Address.
Step 4: Stop

Flowchart

C Program: Code

#include<stdio.h>
int main()
{
printf("Name: Psynal");
printf("\n Roll Number:079");
printf("\n Address: Dharan");
return 0;
}

Output

Name: Psynal
Roll Number:079
Address: Dharan

Discussion and Conclusion

Discussion:
The provided code snippet is a basic C program that uses the printf function to display three lines of information: the name "Psynal", the roll number "079", and the address "Dharan". The lines are printed sequentially, one after the other.
Conclusion:
In conclusion, the code snippet effectively demonstrates the use of the printf function to output multiple lines of text. However, it could be further improved by enclosing the text within double quotation marks to ensure proper formatting.

3. WAP to add two integer variables and print sum.

Algorithm:

Step 1: Start
Step 2: Assign any three variables a and b and sum.
Step 3: Get the value of two numbers from the user.
Step 4: Calculate the sum. sum=a+b
Step 5: Display Sum.
Step 6: Stop

Flowchart:

C Program: Code

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter First Number:\n");
scanf("%d",&a);
printf("Enter Second Number:\n");
scanf("%d",&b);
c=a+b;
printf("Sum: %d",c);
return 0;
}

Output:

Enter First Number:
110
Enter Second Number: 120
Sum: 230

Discussion and Conclusion:

Discussion:
The given code basic C program that prompts the user to enter two numbers, reads the input using scanf, calculates their sum, and then prints the result.
Conclusion:
In conclusion, the code showcases the fundamental steps of accepting user input, performing arithmetic operations, and displaying the output in C. However, it does not include any error handling or input validation, which could be implemented to enhance the program's reliability.

4. WAP to multiply two integer variables and print the product.

Algorithm:

Step 1: Start
Step 2: Assign any three variables a and b and c.
Step 3: Get the value of two numbers from the user.
Step 4: Calculate the product. c=a*b
Step 5: Display the product.
Step 6: Stop

Flowchart:

C Program: Code

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter First Number:\n");
scanf("%d",&a);
printf("Enter Second Number:\n");
scanf("%d",&b);
c=a*b;
printf("Multiplication=%d",c );
return 0;
}

Output:

Enter First Number:
10
Enter Second Number:
15
Multiplication=150

Discussion and Conclusion:

Discussion:
The code prompts the user to enter two numbers. It then multiplies the entered numbers and stores the result in the variable 'c'. Finally, it prints the multiplication result.
Conclusion:
This code takes user input for two numbers, performs multiplication, and displays the result.

5. WAP to calculate and display the simple interest.

Algorithm:

Step 1: Start
Step 2: Read the principal amount (P), interest rate (R), and time period (T) from the user.
Step 3: Calculate the simple interest using the formula: SI = (P * R * T) / 100.
Step 4: Display the calculated simple interest (SI).
Step 5: Stop.

Flowchart:

C Program: Code

#include <stdio.h>
int main()
{
int p,t;
float r,i,f;
printf("Enter Principal:\n");
scanf("%d",&p);
printf("Enter Time:\n");
scanf("%d",&t);
printf("Enter Rate of Interest \n");
scanf("%f",&r);
i=p*t*r;
f=i/100;
printf("Simple Interest is %f",f);
return 0;
}

Output:

Enter Principal:
1100
Enter Time:
1
Enter Rate of Interest
5
Simple Interest is 55.000000

Discussion and Conclusion:

Discussion:
The code prompts the user to enter values for principal, time, and rate of interest. It then calculates the simple interest and stores it in the variable 'f'. Finally, it prints the calculated simple interest.
Conclusion:
This code takes user input for principal, time, and rate of interest, calculates the simple interest, and displays the result.

Algorithm:

Flowchart:

C Program: Code

#include<stdio.h>
#define pi 3.1415
int main()
{
float r,a;
printf("Enter the radius of Circle:\n");
scanf(“%f”,&r);
a=pi*r*r;
printf("Area of Circle is %f",a);
return 0;
}

Output:

Enter the radius of Circle:
1
Area of Circle is 3.141500

Discussion and Conclusion:

Discussion:
The code calculates the area of a circle based on the user input of the radius. It uses the defined constant pi and the formula a=pi*r*r to calculate the area.
Conclusion:
The code successfully takes the radius of a circle as input, calculates the area using the defined constant pi and the formula a=pi*r*r, and displays the result.
C Programming Lab
A free online educational resource provider.

Post a Comment

We get inspired from your single comment.

Cookies Consent

This website uses cookies to ensure you get the best experience on our website.

Cookies Policy

We employ the use of cookies. By accessing Lantro UI, you agreed to use cookies in agreement with the Lantro UI's Privacy Policy.

Most interactive websites use cookies to let us retrieve the user’s details for each visit. Cookies are used by our website to enable the functionality of certain areas to make it easier for people visiting our website. Some of our affiliate/advertising partners may also use cookies.