ioe solutiion 2067 c programming
1.What is high level programming languages? what are the different type of high level programming languages ? ow computer programming language C is differ from FORTAN
High level language are intended to be machine independent and problem orinted language.first high level language released was FORTAN.
type of high level language
(1) procedural language:general purpose programming language are called procedural language they provide facilities for programmer to express procedure or algorithms.they language such as Pascal,BASIC.
(2) problem-orinted language:design to solve specific problems or develop specific application by enabling you to dscribe what we want rather than step-by step procedure for getting there.example is Database language
(3) natural language:these language are still in development stages .particularly in the areas of artificial intelligence &expart system
DIFFERENT BETWEEN C&FORTAN
1.computer programing language are design to make the connection that human have with computer move natural-more humanlike but FORTAN is specifies and mostly used for engineering and scientific field
2.array index in C start from 0 but started 1 in FORTAN.
3.FORTAN is case insensetive but C is case sensetive language.
4.way of using logical operator in FORTAN and C is al.so different
Operation FORTAN notation C notation
Less than .LT. <
greater than .GT. >
equal to .EQ. ==
not equal to .NE. !=
Greater or equal .GE. >=
less or equal .LE. <=
2.WRITE an algorithm and flowchart of the distance betwn two points(x1,y1)and(x2,y2) governed by formula D2=(x2-x1)2+(y2-y1)2,where x1,x2,y1,y2 are given by user but shouldn’t be zero.
Algorithm
step 1:start
step 2:declare variable x1,x2,y1,y2,D
step 3:READ the cordinate of points x1,x2 & y1,y2
step 4:if x1=0 orx2=0 ory2=0 ory1=0 goto step 3 otherwise
step 5:calulate D=SQRT((X2-X1)2+(Y2-Y1)2)
STEP 6:DISPLAY the value of D
step 7 :stop
Flow chart
start
declare variable x1,x2,y1,y2,D
READ x1,x2 & y1,y2
Is x1=0 orx2=0 ory2=0 ory1=0
calulate D=SQRT((X2-X1)2+(Y2-Y1)2)
display D
Stop
3.write a syntax used in C programming languages for the following:
(a)scanf() (b).while (c).struct (d). if…..else (e).static
syntax of
(a)scanf():
scanf(“control string”,arg1,aer2….arg n);
(b)while :
while(test conditoin)
{
body of the loop
}
(c)struct:
struct tag-name
{
data_type member 1;
data_type member 2;
…….. ……..;
…….. ……..;
};
(d)if..else:
if (test expression)
{
true bolckstatement
}
else
{
false statement
}
statement-x
(e)static:
static data_type var1,var2….var n;
4.what are the significant meanings of ‘&’ and’*’ established in C programming language ? How can you differentiate betn ‘call by value’ and ‘call by reference’with example in c programming language?
& operator vs * operator
& operator:- is a unary considerd as”adress of operator.the & operator when applied to a variable returns it’s address(pointer to variable).it is also called reference operator .
*operator:-is a uiary operator considerd as value at the adress”operator.the*operator when applied to a pointer(address),fetches the value at that address.it is also called dereference operator.
call by the value means to call the functionb passing the value as argument to the function. in this method,changes made to the formal argument in the called function has no effect on the value of actual argument in the calling function.
Example
#Include<stdio.h>
#include<conio.h>
void sum(int,int);
void main()
{
int a=5,b=6;
sum(a,b); \call by value
getch();
}
void sum (intx,inty);
{
printf(“sum=%d”,x+y);
}
Call by reference means to call the function by passing address(reference)as argument to the function.in this method,we can change thevalue of actual argument from the called function.
EXAMPLE
#Include<stdio.h>
#include<conio.h>
void sum(int*,int*);
void main()
{
int a=5,b=6;
sum(&a,&b); \call by reference
getch();
}
void sum (int*x,int*y);
{
printf(“sum=%d”,x*+y*);
}.
5.State with example ,how switch()function differs from user defineed function in computer programming language C.
switch()function causes a particular group of statements to be chosen from several available groups. The selection is based upon the current value of an expression which is included within the switch function.
user define function i a function whose takes are define by the user. As user define function should always have three parts
1.function prototype or declaration
2.function call
3.function definition
Eg:Example of Switch
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf(“nenter the value of n:”);
scanf(“%d”,&n);
switch(n)
{
case1:
printf(“n you have pressed 1”);
break;
case1:
printf(“n you have pressed 2”);
break;
case1:
printf(“n you have pressed 3”);
break;
default:
printf(“n you have pressed wrong number”);
}
getch();
}
here case blocks are selected according to the value of n entered by user.
EXAMPLE of user define function
#include<stdio.h>
#include<conio.h>
int sum (int,int);
void main()
{
int a,b s;
printf(“n enter two integer numbers”);
scanf(“%d%d”,&a,&a);
s=sum(a,b);
printf(“nsum=%d”,s);
getch();
}
int sum (intx,inty)
{
sum=x+y;
return(sum);
}
here user define function sum () calculate the sum of values of a and b entered by user.
6. Write a pseudocode to find the standard deviation of an array of values in C programming.The
array elements are read form the terminal.Use user defined function to calculate standard deviation
and mean.Standard deviation of n value is given by
SD=sqrt(∑_(i=1)^n=(ˣm-ˣi)^2/n),
where ˣm is mean of the values.
Answer:
A code to find the standard deviation of an array of values in C Programming is as follows:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define SIZE 5
float std_dev(float a[],int n);
float mean(float a[],int n);
void main()
{
float value[SIZE];
int i;
printf(“Enter %d float values:n”,SIZE);
for(i=0;i<SIZE;i++)
{
scanf(“%f”,&value[i]);
printf(“std.deviation is %f n”,std_dev(value,SIZE));
}
getch();
float std_dev(float a[],int n);
{
int i;
float x,sum=0.0;
x=mean(a,n);
for(i=0;i<n;i++)
{
sum+=(x-a[i])*(x-a[i]);
return(sqrt(sum/(float)n));
}
float mean(float a[],int n)
{
int i;
float sum=0.0;
for(i=0;i<n;i++)
{
sum=sum+a[];
return(sum/(float)n);
}
}
The output of the above program is :
Enter 5 float values:
35.0 67.0 79.5 14.20 55.75
std. deviation is 23.231582.
7. Write a program in C programming language according to the output diaplayed below:(to open a file
named RECORD.txt for for the n number of data where Cost,Service charge 5%,VAT 15%, and Toatl Cost
must be calculated by program itself).
Output is:
Item code Description Rate Quantity Cost
001CT Computer 22,000.00 5 110,000.00
007M Cell phone 8,000.00 10 80,000.00
VAT
Service Charge
Total Cost
Answer:
A program in C programming language according to the output displayed is as follows:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
FILE *fp;
int qty,i;
float rate,cost,VAT,sch,tc;
char ic,des;
printf(“Input file name:n”);
scanf(“%s”,filename);
fp=fopen(filename,”w”);
printf(“Input RECORD datann”);
printf(“Item code Description Rate Quantity Cost n”);
for(i=0;i<3;i++)
{
fscanf(stdin,”%s %s %f %d”, ic, des, &rate, &qty);
fprintf(fp,”%s %s %.2f %d”,ic, des, rate, qty);
}
fclose(fp);
fprintf(stdout,”nn”);
fp=fopen(filename,”r”);
printf(“Item code Description Rate Quantity Cost n”);
for(i=1;i<3;i++)
{
fscanf(fp,”%s %s %.2f %d”,ic, des, &rate, &qty);
cost=rate*quantity;
fprintf(stdout,”%-8s %-9s %8.2f %8d %11.2dn”,ic, des, rate, qty,cost);
}
fclose(fp);
}
8. Rewrite program correctly and write output of the given program written in programming lanuage
below.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ar1[11]={‘I’,’o’,’E’,’ ‘,’P’,’U’,’L’,’C’,’H’,’O’,’W’,’K’};
char ar2[11]=”IoE,Pulchowk”;
char ar3[11]={{‘I’},{‘O’},{‘E’},{‘ ‘},{‘P’},{‘U’},{‘L’},{‘C’},{‘H’},{‘O’},{‘W’},{‘K’}};
clrscr();
printf(“n Array1=%cn”,ar1);
printf(“n Array2=%cn”,ar2);
printf(“n Array3=%cn”,ar3);
return 0;
}
Answer:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ar1[11]={‘I’,’o’,’E’,’ ‘,’P’,’U’,’L’,’C’,’H’,’O’,’W’,’K’};
char ar2[11]=”IoE,Pulchowk”;
char ar3[11]={{‘I’},{‘O’},{‘E’},{‘ ‘},{‘P’},{‘U’},{‘L’},{‘C’},{‘H’},{‘O’},{‘W’},{‘K’}};
clrscr();
printf(“n Array1=%cn”,ar1);
printf(“n Array2=%cn”,ar2);
printf(“n Array3=%cn”,ar3);
return 0;
}
The output of given program is:
IoE PULCHOWK
IoE,Pulchowk
IOE PULCHOWK
9. Desscribe the formatted input and output statement in FORTRAN programming language with its syntax.
Answer:
The formatted input and output statements in FORTRAN programming language are:
1.READ statement
FORTRAN uses READ statement for the input of data or for assigning data into
variables from keyboard.Its syntax is:
READ *,input_list
where, input_list is a single variable or variables separated by commas.
READ always starts with a new line and READ statement without variables skips the input line.
2.PRINT Statement
FORTRAN uses PRINT statement for displaying data of corresponding variable on the
screen.Its syntax is:
PRINT*,output_list
where, output_list is a single expression or a list of expressions seaprated by commas
.Each of these expressions is a constant,a variable,or a formula.
The asterik means use the default number of decimal places when the number is written to the
screen.
10. Write a program in FORTRAN to evaluate the following series:
series=1/1^2+1/2^2+1/3^2+… … …+1/n^2
Answer:
A FORTRAN program for finding the sum of the series:
INTEGER N
PRINT *,ENTER THE VALUE OF N
READ *,N
SUM=0.0
DO 10 I=1,N,1
SUM=SUM+1/I**2
10 CONTINUE
PRINT*,THE SUM OF THE SERIES IS,SUM
END
And the required output is:
ENTER THE VALUE OF N 4
THE SUM OF THE SERIES IS 1.423611111111.
