Programming in C Question Bank Solution 1-1
Programming in C Question Bank Solution 1-1
1. Draw the flow chart for finding largest of three numbers and write an algorithm and
explain it.
Ans:
Algorithm
Step 1: Start
Step 2: Declare variables a, b, c
Step 3: Read values of a, b, c
Step 4: if a > b
If a > c
Print a is the greatest number
Else
Print c is the greatest number
Else
If b > c
Print b is the greatest number
Else
Print c is the greatest number
Step 5: Stop
start
Read a,b,c
Is
a>b
?
Is Is
b>c a>c
? ?
a l
Print c Print c Print c
e p
T N
End
S I
C
Source: www.csitnepal.com
2. Find the value of “a” in each of the following statements.
int i=3 , j=4, k=8;
float a =4.5, b = 6.5, c = 3.5;
(a) a = b –i/k+ c/k
(b) a = (b-k)/j + (j+c)/k
(c) a=c-((i+j)/(k+i))*b
(d) a=c –i+j/k+i*b
(e) a=c+j%2+b
(f) a= (b+1)%(c+1)
Ans:
A) a = b-i/k+c/k
= 6.5-3/8+3.5/8
= 6.5-0+0.4375
= 6.9375
B) a = (b-k)/j+(j+c)/k
= (6.5-8)/4+(4+3.5)/8
= -0.375+0.9375
= 0.5625
C) a = c-((i+j)/(k+i))*b
= 3.5-((3+4)/(8+3))*6.5
= 3.5-0*6.5
= 3.5
D) a = c-i+j/k+i*b
= 3.5-3+4/8+3 *6.5
= 3.5-3+0+19.5
= 0.5 + 19.5
= 20
E) a = c+j%2+b
= 3.5+4%2+6.5
= 3.5+0+6.5
= 10
F) a = (b+1)%(c+1)
= (6.5+1)%(3.5+1)
= 7.5%4.5
= Not valid
3. Write a program for the interest charged in installments for following case. A
cassette player costs Rs. 2000. A shopkeeper sells it for Rs. 100 down payment and Rs.
100 for 21 more months. What is the monthly interest Charged?
#include<stdio.h>
a l
#include<conio.h>
e p
void main()
{
T N
S I
C
Source: www.csitnepal.com
float c_price,t_price,t_interest,m_interest; //cost price, total price, total interest,
monthly interest
c_price=2000;
t_price=100+(100*21);//down payment Rs. 100 and Rs. 100 for 21 installments
t_interest=(t_price-c_price)/c_price*100;
m_interest=t_interest/22;//payment is for 22 months
printf("\nThe monthly interest charged is %.2f",m_interest); //result is 0.45% per
month
getch();
}
4. Write a program that uses a “for” loop to compute and prints the sum of a given numbers
of squares.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, n, sum=0;
printf(“Enter the number:”);
scanf(“%d”,&n);
for(i=1;i<n;i++)
{
sum=i*i+sum;
}
printf(“\n Sum=%d”,sum);
getch();
}
5. Write a program to obtain the product of the following matrices and explain it;
Ans:
#include<stdio.h>
#include<conio.h>
void main
{
int a[3][3]={{3,5,7},{2,-3,4,{4,5,2}};
int b[3][2]={{7,6},{6,-5},{4,3}};
int i,j,k,c[3][2];
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
a l
for(k=0;k<3;k++)
e p
N
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
S I T
C
Source: www.csitnepal.com
}
}
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf(“%d”,c[i][j]);
}
printf(“\n”);
}
getch();
}
6. Write a function to add, subtract, multiply and divide two complex numbers(x+iy) and
(c+id).
Ans:
#include<stdio.h>
#include<conio.h>
void add(int,int,int,int);
void sub(int,int,int,int);
void mul(int,int,int,int);
void div(int,int,int,int);
void main()
{
Int x,y,c,d,I;
printf(“Enter real and imaginary part1:”);
scanf(“%d%d”,&x,&y);
printf(“Enter real and imaginary part2:”);
scanf(“%d%d”,&c,&d);
add(x,y,c,d);
sub(x,y,c,d);
mul(x,y,c,d);
div(x,y,c,d);
getch();
}
void add(int r1,int ip1, int r2,int ip2)
{
int realsum,imgsum;
realsum=r1+r2;
imgsum=ip1+ip2;
printf(“The sum of complex numbers=%d+i(%d)\n”,realsum,imgsum);
}
void sub(int r1,int ip1, int r2,int ip2)
{
a l
int realsub,imgsub;
realsub=r1-r2;
e p
imgsub=ip1-ip2;
T N
printf(“The subtraction of complex numbers=%d+i(%d)\n”,realsub,imgsub);
}
S I
C
Source: www.csitnepal.com
void mul(int r1,int ip1, int r2,int ip2)
{
int realmul,imgmul;
realmul=r1*r2;
imgmul=ip1*ip2;
imgmul1=r1*ip2;
imgmul2=r2*ip1;
printf(“The multiplication of complex numbers=
%d+i(%d+%d)%d\n”,realmul,imgmul1,imgmul2,imgmul);
}
7. Write a program which will read a line and delete from it all occurrences of the
word “that”.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
char str[]=”I that love c that programming.”;
int i;
for(i=0;str[i]!=’\0′;i++)
{
if(str[i]==116&&str[i+1]==104&&str[i+2]==97&&str[i+3]==116&&str[i+4]==32)
{
for(;str[i+5]!=’\0′;i++)
str[i]=str[i+5];
str[i]=’\0′;
i=0;
}
}
printf(“%s”,str);
getch();
}
a l
e p
8. What is a pointer and explain its applications? Write a program that uses pointers to copy
an array of double.
Ans:
T N
S I
C
Source: www.csitnepal.com
A pointer is a variable, which contains the address of another variable in memory. We can
have a pointer to any variable type pointers are said to “point to “the variable whose
reference they store.
#include<stdio.h>
#include<conio.h>
double *copy(double a[],int n);
void main()
{
double a[10],*b;
int i;
for(i=0;i<10;i++)
{
scanf("%lf",&a[i]);
}
b=copy(a,10);
for(i=0;i<10;i++)
{
printf("\n%lf",b[i]);
}
getch();
}
double *copy(double a[], int n)
{
double *p;
int i;
for(i=0;i<10;i++)
{
p[i]=a[i];
}
return p;
}
9. Define a structure of employee having data members name, address, age, and salary. Take
data for n employee in an array dynamically and find the average salary.
Ans:
#include <stdio.h>
#include<conio.h>
#include<alloc.h>
struct employee
{
char name[50];
a l
char add[50];
int age;
e p
int salary;
T N
};
S I
C
Source: www.csitnepal.com
void main()
{
struct employee *p;
int i, n;
float avg,sum=0;
printf("Enter the number of employee:");
scanf("%d", &n);
p=(struct employee *) calloc (n,sizeof(struct employee));
if(p==NULL)
exit();
for(i=0;i<n;i++)
{
fflush(stdin);
printf("Enter name:");
gets((p+1)->name);
printf("Enter address:");
gets((p+i)->add);
printf("Enter age:");
scanf("%d",&(p+i)->age);
fflush(stdin);
printf("Enter salary:");
scanf("%d",&(p+i)->salary);
}
for(i=0;i<n;i++)
{
sum=sum+(p+i)->salary;
}
avg=sum/n;
printf("Average salary=%f",avg);
getch();
}
10. Given a text file, create another text file deleting the following words “three”,
“bad”, and “time”.
OR
Why do you require graphical function? Explain the basic graphical function with
suitable program.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char str;
fp=fopen("old.txt","r+");
while(fscanf(fp,"%s",str)!=EOF)
a l
{
e
if(strcmp(str,"three")==0||strcmp(str,"bad")==0||strcmp(str,"time")==0) p
{
printf("");
T N
}
S I
C
Source: www.csitnepal.com
else
printf("%s ",str);
}
fclose(fp);
getch();
}
OR
Graphical function in c is used to implement various graphical symbols and shapes. There are
various types of graphics function used. Such as
a. Line(x1,y1,x2,y2)
b. Circle(x,y,r)
arc function is used to draw an arc with center (x,y) and stangle specifies starting
angle, endangle specifies the end angle and last parameter specifies the radius of
the arc. arc function can also be used to draw a circle but for that starting angle and
end angle should be 0 and 360 respectively.
a l
e p
T N
S I
C
Source: www.csitnepal.com
Subject: Fundamental of Computer Programming Year: 2066
1. Why flow chart is required? Explain different symbols used in the flow chart and
explain with suitable example.
Ans:
A flowchart is required because of following reasons:
a. It is a better way of communicating the logic of a system to all
concerned .
b. Problem can be analyzed in more effective way.
c. It acts as a guide or blueprint during the system analysis and program
development phase.
d. It helps in debugging process.
#include<stdio.h>
Include<math.h>
main
{
Float p,r,n;
a l
printf(“Please enter a value for the principal(P):”);
e p
scanf(%f,&p):
printf(“Please enter a value for the interest rate(R));
T N
scanf(“%f’,&r);
S I
C
Source: www.csitnepal.com
printf(“Please enter a value for the number o f years(n):”);
scanf(“%f,n);
f = p *pow +r/100),n);
printf(\n The final value(F) is: %.2f \n”,f);
Ans:
#include<stdio.h>
#include<math.h>
void main()
{
float p,r,n,f;
printf(“Please enter a value for the Principal(P)”);
scanf(“%f”,&p);
printf(“Please enter a value for the Interest Rate(R)”);
scanf(“%f”,&r);
printf(“Please enter a value for the number of years(n)”);
scanf(“%f”,&n);
f=pow((p+r/100),n);
printf(“\n The final value is: %f \n”,f);
}
4. Write a program that uses a “while” loop to c ompute and prints the sum
of a given numbers of squares.For example, if 4 is input, then the program
will print 30,which
is equal to 1 2 +2 2 +3 2 +4 2 .
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,n,sum=0;
printf (“Enter the number:”);
scanf(“%d”,&n);
while (i<n)
{
sum=i*i+sum;
i++;
}
printf(“\n Sum=%d”,sum);
getch();
}
5. Write a program to enter two 3x3 matrices and calculate the
product of given matrices.
a l
Ans:
e p
#include<stdio.h>
#include<conio.h>
T N
void main()
S I
C
Source: www.csitnepal.com
{
int a[3][3],b[3][3],c[3][3];
int i,jk;
printf(“Enter matrix A: \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“Enter matrix B: \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
C[i][j]=0;
for(k=0;k<3;k++)
{
C[i][j]+=a[i][k]*b[k][j];
}
}
}
printf(“\n Product of two matrix: \n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%d”,c[i][j]);
}
printf(“\n”);
}
getch();
}
6. Explain the use of two dimensional arrays. Illustrate it with
suitable program and explain it.
a l
Ans:
e p
A two-dimensional array is arrays which are arranged in two
N
directions: horizontal and vertical. The data items arranged in horizontal
T
S I
C
Source: www.csitnepal.com
direction are referred as rows and the data items arranged in vertical
direction are referred as co lumns.
#incldue<stdio.h>
#incldue<conio.h>
void main()
{
int A[4][4];
printf(“Enter any 2 2 matrix\n”);
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
scanf(“%d”,&A[i][j]);
}
}
printf(“Enterd matrix is \n”);
for(i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
printf(“%3d”,A[i][j]);
}
}
getch();
}
7. Write and test the following power () function that returns x raised to
the power n,
where n can be any integer:
double power(double x, int p)
Ans:
#include <stdio.h>
double power(double x, int p);
void main()
{
double x = 0.0;
int p = 0;
for(x = 2.0 ; x<= 5.0; x ++)
{
for(p = 0 ; p<5 ;p++)
S I
C
Source: www.csitnepal.com
return 1.0;
else
return x * power( x , p - 1 );
}
9. Why structure is required? Make a program using structure of booklist
having data
member’s title, author, and cost. Enter four data and calculate total cost.
Ans:
A structure is required because it provides a means of grouping
variables under a single name for easier handling and identification.
#include<stdio.h>
#include<conio.h>
struct book
{
char title[50];
char author[50];
int cost;
};
void main()
{
struct book P;
int i,sum=0;
for(i=0; i<4;i++)
{
printf(“Enter book title \n”);
gets(P[i].title);
printf(“Enter Author name: \n”);
gets(P[i].author);
printf(“Enter cost of book: \n”);
scanf(“%d”,&P[i].cost);
sum=sum+P[i].cost;
}
printf(“Total cost of books:”,%d”sum);
getch();
}
10. Create a text file and enter “to write a good program is very
time consuming job. “Create another text which contains reverse of above
text.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
a l
FILE *fp,*f;
e p
int i;
T N
char str[]= "To write a good prog ram is very time consuming";
fp=fopen("old.txt","w");
S I
C
Source: www.csitnepal.com
fputs(str,fp);
f=fopen("new.txt","w");
for(i=strlen(str);0<i;i --)
fputc(str[i],f);
fclose(fp);
fclose(f);
}
OR
C graphical function is used to draw different shapes, display text in different fonts,
change colors and many more. Using functions of graphics.h we can make graphics
programs, animations, projects and games. We can draw circles, lines, rectangles, bars and
many other geometrical figures.
Example:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
Void main()
{
int gd = DETECT, gm;
a l
e p
T N
S I
C
Source: www.csitnepal.com
Subject: Fundamental of Computer Programming
2067
1. Draw the flowchart for the solution of a quadratic equation and write algorithm and explain
it.
Ans:
Algorithm:
Step 1: Input a, b, c
Step 2: d = sqrt (b2 – 4 x a x c
Step 3: x1 = (–b + d) / (2 x a)
Step 4: x2 = (–b – d) / (2 x a)
Step 5: Print x1 and x2
Flowchart:
3. A machine is purchased which will produce earning of Rs. 20000 per year while it lasts. The
machine costs Rs. 120000 and will have a salvage value of Rs. 20000 when it is condemned. If
the 12 percent per annum can be earned on alternative investmenst what should be the
minimum life of the machine to make it a more attractive investment compared to
alternative investements?
Ans:
Do yourself
Do yourself
5. Write a program that uses a do…while loop to compute and prints the sum of squares given
n numbers.
Ans:
#include < stdio.h >
void main()
{
Int n;
int sum=0;
printf(“upto which number?:”);
scanf(“%d”,&n);
do
{
sum+=(n*n);
n--;
}
while(n>0);
printf(“sum=%d”,sum);
getch();
}
T N
int count,i,len;
S I
C
Source: www.csitnepal.com
char str[100];
printf("enter the sentence");
gets(str);
len=strlen(str);
for(i=0;i<=len;i++)
{
while(str)
if(str[i]==' ') count++;
}
printf("the number of words are :\t%d",count+1);
}
8. Why pointer is called jewel of C language? Write a program that uses pointers to copy an
array of integer.
Ans:
OR
Explain the importance of pointer. Write a function that is passed an array of n pointers to
floats and returns a newly created array that contains those n float values.
Ans:
Firstly, a number of things you do all the time use pointers, even if you are not aware. A struct
is a pointer. An array is a pointer. A string is a pointer. A class is a pointer. There is no way of
representing a number of associated objects without using pointers in some form or another.
Also, pointers are useful for efficiency. If you pass ten thousand ints to a function, you will have
a substantial time penalty, unless you pass a pointer to an array of ten thousand ints.
a l
9. Define a structure of student having data member’s name, address, marks in C language, and
e
marks in information system. Take data for n students in an array dynamically and find the p
total marks obtained.
T N
S I
C
Source: www.csitnepal.com
Do yourself
10. Some text file is given; create another text file replacing the following words “Ram” to
“Hari”, “Sita” to “Gita”, and “Govinda” to “Shiva”.
Ans:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
main()
{
FILE *ptr,*ptr1;
int i=0,j,n[10],k=0,l;
char line[150],word1[30],word[30];
printf("* This Is A Program To Replace The Words 'Ram' to 'Hari', 'Sita' to 'Gita', & 'Govinda'
to 'Shiva' . *\n\n");
printf("Enter Your String : ");
gets(line);
l=strlen(line);
for(i=0;i<l;i++)
{
if(line[i]==' ')
k++;
}
T N
{
S I
C
Source: www.csitnepal.com
fscanf(ptr,"%s",&word);
if(strcmp(word,"Ram")==NULL)
{
printf("%s ","Hari");
fprintf(ptr1,"%s ","Hari");
}
else if(strcmp(word,"Sita")==NULL)
{
printf("%s ","Gita");
fprintf(ptr1,"%s ","Gita");
}
else if(strcmp(word,"Govinda")==NULL)
{
printf("%s ","Shiva");
fprintf(ptr1,"%s ","Shiva");
}
else
{
fprintf(ptr1,"%s ",word);
printf("%s ",word);
}
}
fclose(ptr);
getch();
}
OR
What are the uses of graphical function? Explain the basic graphical function with suitable
program.
Ans:
The use of graphical function in c programming is to draw the graphics in the c console.
Different shapes can be drawn using graphical function in c.
There are numerous graphics functions available in c. But let us see some to have an
understanding of how and where a pixel is placed in each when each of the graphics
function gets invoked.
a l
putpixel(x, y, color)
e p
T N
S I
C
Source: www.csitnepal.com
->The functionality of this function is it put a pixel or in other words a dot at position x, y
given in inputted argument
getpixel(x, y)
->This function when invoked gets the color of the pixel specified. The color got will be the
integer value associated with that color and hence the function gets an integer value as
return value.
#include<graphics.h>
void main()
initgraph(&gd,&gm,"c:\\tc\\bgi");
circle(200,100,10);
setcolor(WHITE);
getch();
closegraph()
a l
e p
T N
S I
C
Source: www.csitnepal.com
Subject: Fundamental of Computer Programming 2068
1 Write an algorithm and flowchart to determine whether a given integer is odd or
even and explain it.
Ans:
Algorithm
Step 1: Start
Step 2: Read a
Step 4: If r= 0
Print a is even
Else
Print a is odd
Step 5: stop
Flowchat
start
Read a
R = a % 2;
If No
Print a is odd
a l
R=0
e p
T N
S I
C1
C2
C
Source: www.csitnepal.com
C1
yes
Print a is even
start C2
First of all, we have to read an integer a , then find the modules of a by 2 and if the value of
modules is 0 then a is even else a is odd.
Ans:
Variable declaration in C:
Every variable used in the program should be declared to the compiler. The
decleration use two things
Where v1,v2,v3,…….,vn are variables name variables are separated by commas. The
decleration statement must end with a semi colon
Example :
Int sum;
a l
Double average , mean;
e p
2 Write a program to find the factorial of a given integer.
T N
Ans:
S I
C
Source: www.csitnepal.com
Program to find factorial
#include<stdio.h>
Int main()
Int i = 1 , f = 1, num ;
Scanf(“ %d”,&num)
F = f*i;
i++;
Return 0;
Ans:
Switch statement
Switch (expression)
a l
Case case1;
e p
Case case2;
T N
………………..
S I
C
Source: www.csitnepal.com
Case default
Example:
#include<stdio.h>
Void main()
Int num1,num2,result;
Char operator;
Scanf(“%d%d”,&num1,&num2);
Printf(“enter an operator”);
Scanf(“%c”,&operator);
Switch (operator)
Case ‘ + ’ :
Break;
Case ‘ - ‘ :
Break;
Case ‘ * ’ :
Break;
Default:
a l
Printf (“unknown operator”);
ep
Result = 0
T N
Break;
S I
C
Source: www.csitnepal.com
}
4 Write a program to find the largest and smallest among the given element in an
array.
Ans:
#include<sdtio.h>
#include<conio.h>
Void main()
Clrscr();
Int a[10];
Scanf(“ %d ” , a[i] );
Big = a[0];
Big a[i];
a l
Small = a[0];
e p
For ( i=0 ; i<10 ; i++ )
T N
{
S I
C
Source: www.csitnepal.com
If ( small > a[i] )
Small = a[i];
Ans:
User-define function:
The functions which are created by user for program are known as user
defined functions. These type of functions are not defined in C- library and are created by the
user himself. The types of user-defined functions are:
Example:
Void main()
Int n, fac;
Clrscr ();
Fac = fact(n);
Getch ();
a l
}
e p
Int fact (int n)
T N
{
S I
C
Source: www.csitnepal.com
If (n==1)
Return(1);
Else
6 Write a program to accept two number and sort them with using pointer.
Ans:
#include
Void main ()
a = &x;
b = &y;
temp = *b;
*b = *a;
*a = temp;
Ans:
N
individual elements would be hard task. In such cases we may pass whole structure to a
T
function as shown below:
S I
#include<stdio.h>
C
Source: www.csitnepal.com
Structure employee
Int id;
Char name[25];
Float salary;
};
Void main ()
Display(emp1);
Display (emp1);
8 Write a program to accept any number and print the sum of that single digit
through recursive function.
Ans:
#include <stdio.h>
#include<conio.h>
int sum(int);
void main() {
a l
int n;
e p
printf("Enter the single digit number");scanf("%d",&n);
T N
printf("Sum = %d\n", sum(n));
S I
C
Source: www.csitnepal.com
getch();
int sum(int n)
if (n <= 1)
return 1;
else
return (n + sum(n-1));
Ans:
Pointer to structure:
We know the name of array stands for the address of its zero th element the
same concept applies for name of arrays of structures. Suppose item is an array variable of
struct type , consider the following
Struct products
Char name[30];
Int manufac ;
Float net;
Item[2], ptr;
This statement declares item as array of two element, each type struct product and ptr as a
pointer data object of type struct products.
T N
Ptr = name
S I
C
Source: www.csitnepal.com
Ptr = manufac
Ptr = net
OR
Before a program can write to a file or read from file. The program must
open it , opening a file established a link between the program and the operating system, this
provides the operating system, the name of the file and the mode in which the file is to be
opened. The process of establishing a connection between the program and file is called
opening the file.
a l
e p
T N
S I
C
Source: www.csitnepal.com
2069
1 Write an algorithm and flowchart to find out whether a given integer is zero, positive,
negative and explain it.
Ans:
Start
Input a;
If If
Print A is Positive
A<0 B=0
No No p
yes yes
End
Explain yourself
a l
e p
2 What are the basic four data types use in C programming? What are its size and range?
Explain.
T N
Ans:
S I
C
Source: www.csitnepal.com
The four types of datatypes used in C programming are:
Int : They are the basic integer valued data types. They take simple numbers containg no decimal
points in them.
Float : They are the longer range data types that are also capable of taking decimal point values.
Char : They are the character storing data types who stores a character within a name specified.
Double : Doubles are the data types who stores a longer range of number.
Ans:
If …..else :-
If …..else statement are the loopong statement that checks the condition and
proceeds forward the logics. The if statements is run only if the condition in if is TRUE Otherwise
the else statement is run.
Example :
#include<stdio.h>
Void main()
Int a, b;
If (a<b)
a l
Printf ( “a is larger”);
e p
}
T N
else
S I
{
C
Source: www.csitnepal.com
Printf(“b is larger”);
Ans:
Break Exit
1. break is used to exit from the loop 1. exit is used to exit from the program
2. break() is not a function, it is part of the 2. exit() is a function
language syntax.
3.break is a keyword 3. exit is a non-returning function that returns
that exits the current construct like loops the control to the operating system
4. break is a control flow statement of the 4. exit(), instead, is a function that says that the
language. It says that next statement to be program must end and control must be given
executed is the one at the end of the loop (or at back to the operating system
the end of the switch statement)
Ans:
Multidimensional array :
Often there is a need to store and manipulate two dimensional data structure such
as matrices and tables. Here the array has two subscripts one subscript denotes the row and the
other denotes the column. The declaration of two dimensional array as follows.
Example:
0 0 0
1 1 1
a l
Program to convert lowercase string to uppercase :
e p
#include<stdio.h>
T N
#include<string.h>
S I
#include<conio.h>
C
Source: www.csitnepal.com
Void main()
Int len ;
Clrscr ();
Gets(str);
Strupr(str)
Ans:
The C language is accompanied by a number of standard library functions for various useful tasks.
In particular all input and output operation and all math operations are implemented by library
functions. Header file is required to use library functions.
Example:
#include <stdio.h>
Void main()
{
Display();
}
Void display()
}
a l
e p
Output: my name is ram bahadur kanshakar
T N
S I
7 Write a program to find the sum of all the elements of an array using pointers.
C
Source: www.csitnepal.com
Ans
#include<stdio.h>
#include<conio.h>
Void main()
{
Int sum = 0;
Int * array ;
Int i;
Printf (“enter 10 value:”);
For (i=0;i<10;i++)
scanf(“%d”,*(a+i)
For(int j=0;j<10;j++)
Getch();
Ans:
Pointer arithmetic :
C allows us to add integer or subtract integer from pointer as well as to subtract one
pointer from the other. We can also compare pointer by using the relational operators.
Example :
#include<stdio.h>
a l
Void main()
e p
{
T N
Int *ptr1, *ptr2;
S I
Int a , b , x , y , z;
C
Source: www.csitnepal.com
A=30;
B=60;
Ptr1 = &a;
Ptr2 = &b;
X=*ptr1 + *ptr2 – 6;
Printf(“value of x =%d”,x)
9 Explain the array of structures and write a program to accept record of 15 persons which
has name, age and address and also display them.
Ans:
Array of structure:
Structure information
Int id;
Int age ;
Student[100];
Program :
#include<stdio.h>
#include<conio.h>
Structure student
a l
{
e p
Char name [20];
T N
Int age;
S I
C
Source: www.csitnepal.com
Char address [25];
S1 [15];
Void main()
Int I , j;
For (i=0;i<15;I++)
For (j=0;j<15;j++)
10 What are the three types of input/output functions which support in C-programming?
Explain with example.
Ans:
a) Delimiters
b) Graphics function
Delimiters:
A delimiters is a sequence of one or more characters used to specify the boundry between
separate independent region in plain text or other data strings. An example of delimiters is
the comma character which act as field delimiter in a sequesnce of comma separated
values.
Graphic function:
Circle (x , y , r) etc.
a l
e p
T N
S I
C
Source: www.csitnepal.com