Sample of C Report
Sample of C Report
(COMPUTER SCIENCE-427)
KATHMANDU, NEPAL
2021
TRINITY INTERNATIONAL SS & COLLEGE
Lab sheet #1
(Input/Output Functions)
The objective of a program using input and output functions is to know about
different input and output functions and their use in different programs. It will help
us to be familiar with some frequently used I/O functions like scanf(),printf(),
gets(),puts, putchar() ,getchar() etc. Having used functions, we will be able to input
and output numerical and string related data easily
Table of contents
Input/Output(I/O) Functions:
C language consists of some I/O functions like getchar(), putchar(), gets(), puts()
which are also defined inside stdio.h header file. The printf() and scanf() functions are
known as formatted I/O functions because they can take any type of format of data
from the I/O devices.
Syntax:
printf( "control string", arg1, arg2, ......);
Here control string may consist of any simple characters or format conversion
specifiers or escape sequences and arg1, arg2,.... are arguments (variables) that
represent the individual data item.
Example1:
printf(“Hello”);
Here, the statement consists of simple characters without arguments and will display
output ‘Hello;.
Syntax:
variable_name = getchar();
Here variable_name is a valid C name that has been declared as char type.
The putchar() function is used to display the character contained in the variable name
at the output screen / terminal.
Syntax:
putchar(variable_name);
Where variable_name is a type char containing a character.
scanf()
The scanf function is used to read formatted input data. The format in which input data is to be
provided is specified by the scanf function itself as it's first parameter. The scanf function is written
as -
Note that there must be the same number of format specifiers and addresses as there are input data.
For instance, in the following example:
scanf("%d %f",&x,&y)
Algorithm
Step 1: Start
Step 2: Input three numbers as a , b and c
Step 3: Calculate sum=a+b+c and average=sum/3
Step 4: Display sum and average
Step 5: Stop
Flowchart
CODE
#include<stdio.h>
int main(){
int a,b,c,sum=0;
float average=0;
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
average=(float)sum/3;
return 0;}
Output
Algorithm
Step 1: Start
Step2:Input number as n
Step 3: Use sqrt function to find square root and store it in a
Step 4: Display a
Step 5: Stop
Flowchart
Code
#include<stdio.h>
int main(){
int n,a;
scanf("%d",&n);
a=sqrt(n);
return 0;}
Output
Enter a number: 16
Square root of 16 is 4
Algorithm
Step 1: Start
Step 2: Input p,t,r
Step 3: Use si=p*t*r/100 and a=si+p
Step 4: Display si and a
Step 5: Stop
Flowchart
Code
#include<stdio.h>
int main(){
int p,t,r,si,a;
printf("Enter principal, time and rate : ");
scanf("%d%d%d",&p,&t,&r);
si=p*t*r/100;
a=si+p;
printf(" Simple interest is %d \n ",si);
printf(" Net amount is %d ",a);
return 0;}
Output
Enter principal, time and rate: 1000
2
10
Simple interest is 200
Net amount is 1200
Algorithm
Step 1: Start
Step 2: Input initial velocity, time and accelaration as u,t,a
Step 3: Use s=u*t+0.5*a*t*t
Step 4: Display s
Step 5: Stop
Flowchart
Code
#include<stdio.h>
int main(){
float u,t,a,s;
printf(" Enter initial velocity , time and acceleration : ");
scanf("%f%f%f",&u,&t,&a);
s=u*t+0.5*a*t*t;
printf(" Distance covered is %0.2f ",s);
return 0;}
Output
Program no.5
Program to calculate area and circumference of a circle
Algorithm
Step 1: Start
Step 2: Input radius as r
Step 3: Use a=3.14*r*r and c=2*3.14*r
Step 4: Display a and c
Step 5: Stop
Flowchart
Code
#include<stdio.h>
int main(){
float r,a,c;
printf(" Enter radius : ");
scanf("%f",&r);
a=3.14*r*r;
c=2*3.14*r;
printf(" Area = %.2f \n Circumference = %.2f ",a,c);
return 0;}
Output
Enter radius : 1
Area = 3.14
Circumference = 6.28
Q6.Program to convert Centigrade (C) into Fahrenheit (F)
Algorithm
Step 1: Start
Step 2: Input temperature in centigrade as c
Step 3: Use f=1.8*c+32
Step 4: Display f
Step 5: Stop
Flowchart
Program
#include<stdio.h>
int main()
float c,f;
scanf("%f",&c);
f=1.8*c+32;
return 0;
Output
Flowchart
Program
#include<stdio.h>
int main()
int feet1,feet2,feet3,newfeet,inch1,inch2,inch3,newinch;
scanf("%d%d%d%d",&feet1,&feet2,&inch1,&inch2);
feet3=feet1+feet2;
inch3=inch1+inch2;
newfeet=inch3/12+feet3;
newinch=inch3%12;
return 0;
Output
Step 1 Start
Step 2: Input days
Step 3: Divide days by 365 and store it in y
Step 4: Remaining days(rd) =days%365
Step 5: For m= rd/30 and d=rd%30
Step 6: Display y,m,d
Step 7: Stop
Flowchart
Program
#include<stdio.h>
int main()
{
int days,y,m,d,rd;
printf(" Enter the days: ");
scanf("%d",&days);
y=days/365;
rd=days%365;
m=rd/30;
d=rd%30;
printf(" Year=%d Month=%d Day=%d",y,m,d);
return 0;
}
Output
Enter the days: 370 Year=1 Month=0 Day=5
Q9.Complete the programs and discuss the output
#include<stdio.h>
int main()
float x;
int x1=5;
int x2=2;
x=x1/x2;
printf("%f",x);
return 0;
Output
2.000000 In this
case, implicit type conversion is used which convert the final data(x) into float data type not x1
and x2.
#include<stdio.h>
int main()
float x;
int x1=5;
int x2=2;
x=(float)x1/x2;
printf("%f",x);
return 0;
Output
2.500000
Conclusion: In this case, explicit type conversion is used which convert the x1 and x2 into float
before the division.
Q10.Complete the programs and discuss the output
Program 1
#include<stdio.h>
int main()
int j;
int i=5;
j=++i;
return 0;
Output
i=6
j=6
Conclusion: (++i) is Prefix increment unary operator first adds 1 to the operand and then the
result is assigned to the variable on the left.
Program 2
#include<stdio.h>
int main()
int j;
int i=5;
j=i++;
return 0;
Output
i=6
j=5
Conclusion: (i++) is Postfix increment unary operator first assigns the value on the left and then
increments the operand
Conclusion
It was a wonderful time in the lab and classroom while learning. The outcome of the learning is
great and is very similar to the prediction made in the beginning. We learned about input and
output functions in detail. It helped us a lot in our programming. We came to know its syntax,
semantic with example. I hope that this will help us in future in my project work. At last, I would
like to thank my class subject teacher for his support and cooperation.