Fundamentals of Computer Programming 2065
Attempt all questions:
AI is thinking...
1. Draw the flow chart for finding largest of three numbers and write an algorithm and explain it.
Algorithm:
1. Start
2. Input A,B,C
3. If (A>B) and (A>C) then print “A is greater”.
Else if (B>A) and (B>C) then print “B is greater”.
Else print “C is greater”.
4. Stop
Flowchart:
AI is thinking...
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).
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.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
AI is thinking...
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>
#include<conio.h>
void main()
{
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 %f", m_interest); //result is 0.45% per month
getch();
}
AI is thinking...
4. Write a program that uses a “for” loop to compute and prints the sum of a given numbers of squares.
#include<stdio.h>
int main()
{
int i, n, sum=0;
printf("Enter n value: ");
scanf("%d", &n);
for(i=0; i<=n; i++)
{
sum += (i*i);
}
printf("Sum of squares of first %d natural numbers = %d", n, sum);
return 0;
}
AI is thinking...
5. Write a program to obtain the product of the following matrices and explain it:
#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;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf("%d", c[i][j]);
}
printf("\\n");
}
getch();
}
AI is thinking...
6. Write a function to add, subtract, multiply, and divide two complex numbers (x +iy) and (c + id).
AI is thinking...
7. Write a program which will read a line and delete from it all occurrences of the word
“that”.
AI is thinking...
8. What is a pointer and explain its applications? Write a program that uses pointers to copy an array of double.
OR
Define a pointer. Write a function that is passed an array of n pointers to the maximum of the floats.
AI is thinking...
9. Define a structure of employee having data members name, address, age, and salary. Take data for employee in an array dynamically and find the average salary.
AI is thinking...
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.
AI is thinking...