0% found this document useful (0 votes)
15 views18 pages

Wa0034.

The document outlines a series of C programming experiments conducted by Prachi Singh, including problems such as basic arithmetic operations, temperature conversion, length conversion, and calculating CGPI based on marks and attendance. Each program includes an algorithm, flowchart, and the corresponding C code. The conclusion emphasizes the learning experience gained from applying programming concepts and problem-solving skills.

Uploaded by

nknows1607
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)
15 views18 pages

Wa0034.

The document outlines a series of C programming experiments conducted by Prachi Singh, including problems such as basic arithmetic operations, temperature conversion, length conversion, and calculating CGPI based on marks and attendance. Each program includes an algorithm, flowchart, and the corresponding C code. The conclusion emphasizes the learning experience gained from applying programming concepts and problem-solving skills.

Uploaded by

nknows1607
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/ 18

Name Prachi Singh

UID no. 2024800119

Experiment No. 1
AIM:
Use the formatted input/output statements, operators and
expressions of C language
Program 1

PROBLEM Write a C program to input 2 numbers. Perform addition, subtraction,


STATEMENT : multiplication, division and modulus and display output.
ALGORITHM: 1.Start

2.Declare integer variables a and b.

3.Read the values of a and b from the user.

4.Display the sum of a and b: a + b.

5.Display the subtraction of a and b: a - b.

6.Display the multiplication of a and b: a * b.

7.Display the remainder when b divides a: a % b.

8.Display the result of dividing a by b: a / b.

9.End
FLOWCHART:
PROGRAM: #include
<stdio.h> int
main()
{
int a,b; printf("Enter 2 numbers\n");

scanf("%d %d", &a,&b);

printf("\nThe sum is %d",(a+b));

printf("\nThe subtraction is %d",(a-b));

printf("\nThe multiplication is %d",(a*b));

printf("\nThe remainder on dividing %d by %d is %d",b,a,


(a%b)); printf("\nThe value of %d/%d is %d",a,b,(a/b));
return 0;
}
RESULT:

Program 2
PROBLEM WAP to Convert Celsius to Fahrenheit. Answer should be rounded
STATEMENT : upto 3 decimal places.

ALGORITHM: 1.Start

2.Declare double variables Celsius and Fahrenheit.


3. Display "Enter temperature in Celsius".

4. Read Celsius from the user.

5. Calculate Fahrenheit as (Celsius * 1.8) + 32.

6. Display "Temperature in Fahrenheit" and the value of Fahrenheit


rounded to two decimal places.

7. End
FLOWCHART:

PROGRAM: #include <stdio.h>

int main() { double celsius, fahrenheit;


printf("Enter temperature in Celsius: ");
scanf("%lf", &celsius); fahrenheit = (celsius * 1.8) +
32;
printf("Temperature in Fahrenheit: %.2lf\n",
fahrenheit);
return 0;
}

RESULT:

Program 3

PROBLEM WAP to Convert Foot to Meter. Answer should be rounded upto 3


STATEMENT: decimal places.
ALGORITHM: 1. Start

2. Declare double variables feet and meters.

3. Input the length in feet from the user.

4. Convert the length from feet to meters using the formula:

5. Meters= feet multiplied by 0.3048 (1 foot = 0.3048 meters).

6. Display "Length in meters" followed by the value of meters


rounded to three decimal places.

7. End

FLOWCHART:
PROGRAM: #include<stdio.h>

void main()

float e,m;

printf("Enter the value in feet");

scanf("%f",&e);

m=e*0.305;

printf("The value in meters is %f\n", m);

RESULT:

Program 4
PROBLEM Write a C program to convert days into year, month and days.
STATEMENT:
ALGORITHM: 1.Start

2.Declare integer variables days, years, months, remaining_days.


3.Display "Enter the number of days".

4.Read the value of days from the user.

5.years = days / 365 (since 1year= 365 days).

6.remaining_days = days - (years * 365).

7.months = remaining_days / 30 (since 1 month= 30 days on average).

8.remaining_days = remaining_days - (months * 30).

9.Display years.

10.Display months.

11.Display remaining_days.

12.End
FLOWCHART:
PROGRAM: #include <stdio.h>

int main() { int days, years, months,


remaining_days;

printf("Enter the number of days: ");


scanf("%d", &days);

years = days / 365;


remaining_days = days-
(365*years);

months = remaining_days / 30;


remaining_days = remaining_days-
(30*months);

printf("Years: %d\n", years);


printf("Months: %d\n", months);
printf("Days: %d\n", remaining_days);

return 0;
}

RESULT:
Program 5
Create a program that asks the user for a number, calculates its square
PROBLEM
and cube, then prints the results. Write the solution both with and
STATEMENT:
without using the math library.
ALGORITHM: 1. Start the program.
2. Import the math library.
3. Prompt the user to enter a number.
4. Read the user’s input and store it as a variable
5. Calculate the square of the number using math.pow (square=
math.pow(number,2))
6. Calculate the cube of the number using math.pow (cube=
math.pow(number,3)).
7. Print the results.
8. End the program.
FLOWCHART:

PROGRAM: #include <stdio.h>


#include <math.h>
Void main () {
int x;
int xsq, xcu, xsqm, xcum;
printf(“Enter the value of x:”);
scanf(“%d”,&x);
xsq= x*x;
xcu= x*x*x;
xsqm= pow(x,2);
xcum= pow(x,3);
printf(“square of x without math lib: %d\n”, xsq);
printf(“square of x with math lib:%d\n”, xsqm);
printf(“cube of x without math lib:%d\n”, xcu);
printf(“cube of x without math lib:%d\n”, xcum);
}
RES
ULT:

Program 6

Write a C program to calculate the CGPI based on subject marks (each


subject out of 100) and attendance for each subject. The program should
take input for the marks of each subject and whether attendance for that
subject is above or below 75%
PROBLEM
STATEMENT: Input 0 if attendance is less than 75%vfor a subject.
Input 1 if attendance is greater than or equal to 75% for a subject.
If the attendance is below 75% for a subject (i.e., input is 0), the program
should ignore the marks for that subject and consider them as 0 when
calculating the CGPI.
ALGORITHM: Initialize Variables:
1. a1, a2, a3, a4, a5 (attendance)
2. m1, m2, m3, m4, m5 (marks)
3. A, B, C, D, E (weighted scores)
4. Q (total score), R (CGPI)
5. TOTAL_MARKS = 50.0
6. Input Attendance:
7. Prompt and read a1 to a5.
8. Input Marks:
9. Prompt and read m1 to m5.
10. Calculate Weighted Scores:
11. A = m1 * a1
12. B = m2 * a2
13. C = m3 * a3
14. D = m4 * a4
15. E = m5 * a5
16. Calculate Total Score:
17. Q = A + B + C + D + E
18. Calculate CGPI:
19. R = Q / TOTAL_MARKS
20. Output CGPI:
21. Print R (formatted to two decimal places).
22. End.
FLOWCHART:

PROGRAM: #include<stdio.h>
void main()
{
float A,B,C,D,E,Q,R,m1,m2,m3,m4,m5,a1,a2,a3,a4,a5;
printf("The attendance of subject m1");
scanf("%f", &a1);
printf("The attendance of subject m2");
scanf("%f",&a2);
printf("The attendance of subject m3");
scanf("%f",&a3);
printf("The attendance of subject m4");
scanf("%f",&a4);
printf("The attendance of subject m5");
scanf("%f",&a5);
printf("Enter marks of subject 1");
scanf("%f",&m1);
printf("Enter marks of subject 2");
scanf("%f",&m2);
printf("Enter marks of subject 3");
scanf("%f",&m3);
printf("Enter marks of subject 4");
scanf("%f", &m4);
printf("Enter marks of subject 5");
scanf("%f",&m5);
A=m1*a1;
B=m2*a2;
C=m3*a3;
D=m4*a4;
E=m5*a5;
Q=A+B+C+D+E;
R=Q/50.0;

printf("The CGPI is %f\n",R);


}

RESULT:

CONCLUSION: In conclusion, this coding assignment provided a valuable opportunity to


apply programming concepts and problem-solving skills. It reinforced
understanding of key principles such as algorithm design, debugging, and
code optimization. The project not only deepened technical skills but also
highlighted the importance of writing clean, maintainable code. Overall, it
was a beneficial exercise in both practical coding and theoretical
understanding.

You might also like