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

Lab Report On C Programming For Grade 12 1

The lab report summarizes 6 programming labs completed by the student. Each lab involved writing a C program to solve a computational problem, such as calculating area, averages, or interest. For each lab, the student explained the objective, provided the source code, and concluded the program achieved the intended result. Overall, the report demonstrates the student's ability to write various C programs to perform common mathematical calculations.

Uploaded by

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

Lab Report On C Programming For Grade 12 1

The lab report summarizes 6 programming labs completed by the student. Each lab involved writing a C program to solve a computational problem, such as calculating area, averages, or interest. For each lab, the student explained the objective, provided the source code, and concluded the program achieved the intended result. Overall, the report demonstrates the student's ability to write various C programs to perform common mathematical calculations.

Uploaded by

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

Lab Report of C Programming

College Logo Here

Submitted To
Department of Management
For the Partial fulfillment of
Computer Science (com. 232)
BAC international College, Kathmandu
2077BS

Submitted By
Name: Ram Thapa Magar
Grade: Twelve
Roll No.:
Date: 2077/00/00

1
Lab No. 1

Question: Write a Program to print Hello world using C-programming.


Objective: to display hello world using C programming
Theory: First of all we declare the header files, main function and print the message using
printf(); function and getch() used for holding the console result.
Algorithm:
Step 1: start
Step 2: print a message of "hello world"Step 3: end
Source Code:
#include<stdio.h>
#include<conio.h>
main()
{
printf("hello world");
getch();
}

Conclusion: The message hello world has been successfully run and gets the accurate result.

2
Question: Write a program using escape sequence.
Objective: To display program using escape sequence.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a value of x and y.
Step 3: Calculate sum, sub and mul
Step 4: Print the value of x and y
Step 5: End
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,sum,sub,mul;
printf("Enter a value of x:");
scanf("%d",&x);
printf("Enter a value of y:");
scanf("%d",&y);
printf("The result of sum is =%d\n",sum=x+y);
printf("The result of sub is =%d\n", sub=x-y);
printf("The result of mul is =%d\n", mul=x*y);
return 0;
getch();
}

3
Conclusion: A program using escape sequence successfully run.

4
Lab No. 2

Question: Write a program to print variables values using format specifiers.


Objective: To print variables values using format specifiers in C-programming.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a value of x, y and z.
Step 3: print the value of x, y and z.
Step 4: End
Source Code:
#include<stdio.h>
#include<conio.h>
main()
{
int x;
float y;
char z;
printf("Enter a value of x,y and z:");
scanf("%d%f%c",&x,&y,&z);
printf("The value of x=%d \n y=%f \n z=%c",x,y,z);
getch();
}

Conclusion: A program using format specifier successfully run.


5
Question: Write a program to get input from users and display them.
Objective: To display input from users.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a value of x, y and z.
Step 3: Read the value of x,y,z.
Step 4: print the result
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
main()
{
int x;
float y;
char z;
printf("Enter a value of x,y and z:");
scanf("%d%f%s",&x,&y,&z);
printf("The value of x=%d \n y=%f \n z=%s",x,y,z);
getch();
}

Conclusion: A program using input from users successfully run.


6
Lab No. 3

Question: Write a program to get input from users and swap the value.
Objective: To display the input from users and swap the value.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a value of x, y and z.
Step 3: swap the x to y and y to z.
Step 4: print the value of x and y.
Step 5: End
Source Code:
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,extra;
printf("Enter a value of x:");
scanf("%d",&x);
printf("Enter a value of y:");
scanf("%d",&y);
extra=x;
x=y;
y=extra;
printf("x=%d \n y=%d",x,y);
return 0;
getch();
}

7
Conclusion: A program using input from users and swap successfully run.

Question: Write a program to collect values from users and calculate square.
Objective: To display the calculation of square using c programming.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a value of x.
Step 3: Calculation of square = x*x
Step 4: print the result of square.
Step 5: End.
Source Cord:
#include<stdio.h>
#include<conio.h>
main()
{
int x, square;
printf("Enter a value of x:");
scanf("%d",&x);
printf("The area of square = %d", square=x*x);
return 0;

8
getch();
}

9
Lab No. 4

Question: Write a program to collect three variables from users and calculate average.
Objective: To display the calculation of average by collecting three variables from users.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a value of x,y and z.
Step 3: Calculation of average = (x+y+z)/3
Step 4: Print the result of square.
Step 5: End.
Source Cord:
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z,avg;
printf("Enter a value of x:");
scanf("%d",&x);
printf("Enter a value of y:");
scanf("%d",&y);
printf("Enter a value of z:");
scanf("%d",&z);
printf("The average is = %d", avg= (x+y+z)/3);
return 0;
getch();
}

10
Conclusion: A program to collect three variables from users and calculate average
successfully run.

11
Lab No. 5

Question: Write a program to calculate simple interest.


Objective: To display the calculation of simple interest.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Start 2: Enter a value of principle, rate and interest.
Step 3: Calculation of simple interest = (principle*rate*time)/100
Step 4: print the result of simple intrest.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
main()
{
int Principle,Time,Rate,SI;
printf("Enter a value of Principle:");
scanf("%d",&Principle);
printf("Enter a value of Time:");
scanf("%d",&Time);
printf("Enter a value of Rate:");
scanf("%d",&Rate);
printf("The simple intrest = %d",SI=(Principle*Time*Rate)/100);
return 0;
getch();
}

12
Conclusion: A program to calculate simple interest.

Question: Write a program to calculate compound interest.


Objective: To display the calculation of compound interest.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a principle, time and rate.
Step 3: Calculation of compound interest = P(1+R/100)t-1
Step 4: print the result of compound intrest.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float P,T,R,CI;
printf("Enter a principle:");
scanf("%f",&P);
printf("Enter a time:");
scanf("%f",&T);

13
printf("Enter a rate:");
scanf("%f",&R);
CI= P*(pow((1+R/100),T));
CI= CI-P;
printf("Compound Intrest = %f",CI);
return 0;
getch();
}

Conclusion: A program to calculate compound interest successfully run.

Question: Write a program to calculate area of circle.


Objective: To display the calculation of area of circle.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a radius of circle.
Step 3: Calculation of area of circle 𝐴 = 𝜋𝑟 2 .
Step 4: Print the result of area of circle.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
14
{
int radius;
float area;
printf("Enter a radius of circle:");
scanf("%d",&radius);
printf("Area of circle = %f", area=3.14*radius*radius);
return 0;
getch();
}

Conclusion: A program to calculate area of circle successfully run.

15
Lab No. 6

Question: Write a program to calculate student details and division using c programming
Objective: To display the calculation student details and division.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
char name,address;
int rollno,sub1,sub2,sub3,sub4,sub5,total;
float percentage;
printf("Enter your name:");
scanf("%s",&name);
printf("Enter your address:");
scanf("%s",&address);
printf("Enter your rollno:");
scanf("%d",&rollno);
printf("Enter your all 5 subjects marks:");
scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
total=sub1+sub2+sub3+sub4+sub5;
percentage=total/5;
printf("Your percentage is = %f\n",percentage);
if(100&&percentage>=80)
{
printf("You are passed in Distanction");
}

16
else if(percentage<80&&percentage>=60)
{
printf("You are passed in first division");
}
else if(percentage<60&&percentage>=45)
{
printf("You are passed in secound division");
}
else if(percentage<45&&percentage>=35)
{
printf("You are passed in third division");
}
else
{
printf("Sorry!! Better try for next time");
}
return 0;
getch();
}

Conclusion: To calculate students details and division successfully run.

Question: Write a program about age who can drive and cannot.

17
Objective: To display a program age who can drive and cannot.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter your age.
Step 3: Read the age.
Step 4: Condition check according to age.
Step 5: Print the message.
Step 6: End.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if (age<=70&&age>=18)
{
printf("You are above 18 and below 70, you can drive\n");
}
else
{
printf("You cannot drive");
}
return 0;
getch();
}

18
Conclusion: a program about age who can drive and cannot successfully run.

Question: Write to print appropriate message.

If passed Message
A Excellent
B Good
C Fair
D Poor
Objective: To display the program.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a letter
Step 3: Read the letter.
Step 4: Print the appropriate result.
Step 5: End.
Source Code:
#include<conio.h>
#include<math.h>
int main()
{
char x;
printf("Enter a letter:");
scanf("%s",&x);

19
if(x=='A')
{
printf("Excellent");
}
else if(x=='B')
{
printf("Good");
}
else if(x=='c')
{
printf("Fair");
}
else if(x=='D')
{
printf("Poor");
}
return 0;
getch();
}

Conclusion: Display of appropriate message of above table successfully run.

20
Lab No. 7

Question: Write a program for rating (1-5) play store application.


Objective: To display the rating of play store application.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter your rating.
Step 3: Read the rating number.
Step 4: Print the appropriate message.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int rating;
printf("Enter your rating:");
scanf("%d",&rating);
switch(rating)
{
case 1: printf("Your rating is 1\n"); break;
case 2: printf("Your rating is 2\n"); break;
case 3: printf("Your rating is 3\n"); break;
case 4: printf("Your rating is 4\n"); break;
case 5: printf("Your rating is 5\n"); break;
default: printf("Invalid rating!!"); break;
}
return 0;

21
getch();
}

Conclusion: A program for rating (1-5) play store application.

Question: Write a program to read from user and print it is vowel or not.
Objective: To display a program entered letter is vowel or not.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int c;
printf("Enter a character:");
scanf("%d",&c);
switch(c)
{
case 1:'a';
case 2:'A'; printf("vowel"); break;
case 3:'e';
case 4:'E'; printf("Vowel"); break;
case 5:'i';
case 6:'I'; printf("Vowel"); break;

22
case 7:'o';
case 8:'O'; printf("Vowel"); break;
case 9:'u';
case 10:'U'; printf("Vowel"); break;
default: printf("Entered character is not vowel"); break;
}
return 0;
getch();
}

Conclusion: A program to read from user and print it is vowel or not successfully run.

23
Lab No. 8

Question: Write a program to print number 1 to 100.


Objective: To display a program to print number 1 to 100.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a number.
Step 3: Condition check
Step 4: Print the result.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int v;
for(v=1;1<=100;v++);
{
printf("%d",v);
}
return 0;
getch();
}
Conclusion: A program to print number 1 to 100 successfully run but output is blank.

Question: Write a program to calculate multiplication using for loop.


Objective: To display a program to calculate multiplication.

24
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a number.
Step 3: Read a number and condition check.
Step 4: Print the result.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,m;
printf("Enter a number:");
scanf("%d",&n);
for(i=1;i<=10;i++);
{
m=i*n;
printf("Your result is = %d",m);
}
return 0;
getch();
}

25
Conclusion: A program to calculate multiplication using for loop successfully run.

Question: Write a program to calculate power and print.


Objective: To display a program calculating power.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a base number and index number.
Step 3: Red the number and Condition check
Step 4: Print the result.
Step 5: End.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int i,x,y,pow;
printf("Enter a base number and index number:");
scanf("%d%d",&x,&y);
for(i=1;i<=y;i++);
{

26
pow= x*pow;
printf("%d^%d=%d",pow);
}
return 0;
getch();
}
Conclusion: a program to calculate power and print successfully run.

Question: Write a program of alphabetical order using for loop.


Objective: To display the program of alphabetical order.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2:
Source Code:
#include <stdio.h>
int main() {
char c;
for (c = 'A'; c <= 'Z'; ++c)
printf("%c ", c);
return 0;
}

Conclusion: A program of alphabetical order using for loop successfully run.

27
Lab No. 9

Question: Write a program to read number from user and then calculate sum of digits in it
using while loop.
Objective: To display a number from user and calculation of sum.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a number.
Step 3: Read a number and condition check.
Step 4: Print the result.
Step 5: End.
Source Code:
#include <stdio.h>
int main() {
int n,r,sum=0;
printf("Enter a number:");
scanf("%d",&n);
while(n!=0)
r=n%10;
sum= 0+4/sum+r;
n= n%10;
printf("The sum of entered number is = %d",sum);
return 0;
}
Conclusion: a program to read number from user and then calculate sum of digits
successfully run.

Question: Write a program to read number from user then print multiplication table using do
while loop.

28
Objective: To display a multiplication table using do while loop.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: start
Step 2: Enter a number.
Step 3: Read a number and condition check.
Step 4: Print the number.
Step 5: End.
Source Code:
#include <stdio.h>
int main() {
int n,m,i=0;
printf("Enter a number:");
scanf("%d",&n);
do
{
m=n*i;
printf("%d",m);
i++;
}
while(i<=10);
return 0;
}

29
Conclusion: a program to read number from user then print multiplication table successfully
run.

Question: Write a program to calculate the factorial of a given number using for loop.
Objective: To print and display the factorial of given number..
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: To enter a number.
Step 3: Address and read the condition of for loop.
Step 4: print the output.
Step 5: Stop
Source Code:
#include<stdio.h>
int main(){
int i,f=1,num;

printf("Enter a number: ");


scanf("%d",&num);

for(i=1;i<=num;i++)
f=f*i;

printf("Factorial of %d is: %d",num,f);


return 0;
}

30
Conclusion: a program to calculate factorial successfully run.

Question: Write a program to print symbolic pattern.


Objective: To display a program to print symbolic pattern.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a symbol.
Step 3: Read a symbol and condition check.
Step 4: Print the result.
Step 5: End.
Source Code:
#include <stdio.h>
int main()
{
int i,j;
printf("Enter your symbolic pattern:S");
scanf("%d",&j);
for(i=1;i<=5;j++);
{
for(j=1;j<=5;j++);
printf("*");

31
}
return 0;
}
Conclusion: a program to print symbolic pattern successfully run.

32
Lab No. 10

Question: WAP to declare a function 'add' and perform addition operation using function.
Objective: To print and display addition function.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a two number.
Step 3: Add the entered two number
Step 4: Print the result.
Step 5: Stop.
Source Code:
#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{
int a,b,sum;
printf("\n Enter the two number: ");
scanf("%d%d",&a,&b);
sum=add(a,b);
printf("\nAddition of tow number is: %d",sum);
getch();
}
int add(int x, int y)
{
int add=x+y;
return(add);
}

33
Conclusion: A program to calculate sum successfully run.

Question: WAP to declare function 'area' and calculate area of circle using function.
Objective: To display and print the area of circle.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a radius of circle.
Step 3: Calculate the statement
Step 4: Print the outcome of calculation
Step 5: Stop.
Source Code:
#include<stdio.h>
#include<conio.h>
float area(float);
void main()
{
float r,a;
printf("\n Enter the radius of cirlce: ");
scanf("%f",&r);
a=area(r);
printf("\nArea of a circle is : %f",a);

34
getch();
}
float area(float r)
{
float a;
a=3.14*r*r;
return(a);
}

Conclusion: A program to calculate area of circle successfully run.

Question: WAP to read integer from user. Calculate and print its factorial on monitor.
Objective: To print and display the calculation of factorial.
Theory: : First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm
Step 1: Start
Step 2:
Step 3:
Step 4:
Step 5:
Source Code:
#include<stdio.h>
#include<conio.h>
int factorial(int);

35
void main()
{
int x,t;
printf("\nEnter the number : ");
scanf("%d",&x);
t=factorial(x);
printf("\n%d!=%d",x,t);
getch();
}
int factorial(int n)
{
int f;
if(n==1)
{
return 1;
}
else
{
f=n*factorial(n-1);
}
return f;
}

Conclusion: A program to calculate factorial successfully run.

36
Lab No. 11

Question: WAP to read 10 integer in array, calculation sum and average of numbers in array.
Objective: To print and display 10 integer number and calculate sum and average.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2: Enter a ten number
Step 3: Sum a given ten number
Step 4: Calculate it's average and print the given output.
Step 5: Stop.
Source Code;
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,sum=0;
float avg;
for(i=0;i<10;i++)
{
printf("Enter Number %d:",i+1);
scanf("%d",&a[i]);
sum=sum+a[i];
}
avg=sum/10;

printf("\nSum=%d\nAverage=%f",sum,avg);
}
getch();

37
}

Conclusion: Program to read ten integer and calculate sum and average successfully run

Question: WAP to read 3X3 matrix then calculate and print addition of matrix.
Objective: To print and display 3*3 matrix and calculate addition.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm:
Step 1: Start
Step 2:
Step 3:
Step 3:
Step 4:
Step 5:
Source code:
#include<stdio.h>

38
#include<conio.h>
Void main()
{
int a[3][3], b[3][3], sum[3][3], i,j;
printf("Enter a First Matrix: ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
printf("Enter a Second Matrix: ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n Addition of Matrix is: ");
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("%d\t",sum[i][j]);
}
getch();
}
Conclusion: Program to read 3*3 matrix and to calculate addition successfully run.

39
Lab No. 12

Question: WAP to read a string from user and print number of total character in it.
Objective: To print and display a string from user with number of character.
Theory: First of all we declare the header files, main function, print the message using
printf();, scanf() for read character and interprets, function and getch() used for holding the
console result.
Algorithm
Step 1: Start
Step 2: Enter a string
Step 3: Calculate the string
Step 4: condition check and print the output
Step 5: Stop
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
char str[30];
int i=0;
int count=0;
printf("\nEnter The String: ");
gets(str);
while(str[i]!='\0')
{
count++;
i++;
}
printf("\n Total character in string is : %d",count);
getch();
}

40
Conclusion: Program to print string and calculate number of string successfully run.

Bibliography

Manandher, S. (2017). Computer Science. Kathmandu, Nepal: Asmita Publication.


Parachandra Shrestha, S. M. (2017). Coputer Science. Kathmandu: Asmita Publication.

41

You might also like