Вы находитесь на странице: 1из 12

Programming Board Questions

1. Area & Circumference of a Circle. (17, 12, 11, 09, 07)

2. Area & Perimeter of a Triangle. (16)

3. Area & Perimeter of a Rectangle. (10)

4. Convert Fahrenheit to Celsius. (17, 15, 10, 07)

5. Calculate and print a multiplication table 1 to 5. (10)

6. Find the number is Even or Odd. (13)

7. Find the year is Leap year or not. (14)

8. Sum of the series 1 + 1/2 + 1/3 +…. + 1/n. (14)

9. Find the number of and sum of all integers greater than 50 and less than 300 that are
divisible by 9. (11. 08, 07)

10. Prints the largest among three numbers using nested if…else. (15)

11. Display Integer and Factorial point separately.

12. Compute grade of subjects. (16, 13, 06)

13. Test whether a given string is Palindrome or not. (14, 12, 11)

14. Calculate and print first m Fibonacci numbers. (18, 16, 13, 12, 09)

15. Calculate and print first 20th Fibonacci numbers. (11)

16. Given the number is Prime or not.

17. Display Real, Imaginary and Equal Root of a Quadratic Equation. (15, 10, 09, 06)

18. Swap/Interchange the value using Bitwise operator. (12)

19. Calculate the Factorial of a number using Recursion function. (16, 13, 10, 09, 06)

20. Compute the sum of all elements stored in an integer array using pointer. (17, 08)

21. Calculate the sum and average of a set of n number by using array. (15)

22. Compute the sum of the digits of a given integer number. (09, 08)

23. Set all the diagonal elements of a two-dimensional array to 1 and others to 0. (07,06)

THEOVE46MANIA 1
Programming Board Solves
1. Area& Circumference of a Circle: (17, 12, 11, 09, 07)
#include <stdio.h>
#include<math.h>
int main()
{
float r, area, crcm;
printf(“Enter the Radius: “);
scanf("%f", &r);
area = 3.14 * r * r;
crcm = 2 * 3.14 * r;
printf("Area of the Circle is: %.2f", area);
printf("Circumference of the Circle is: %.2f", crcm);
return 0;
}

2. Area of a Triangle using three sides: (16)


Perimeter of a Triangle:
#include <stdio.h>
#include<math.h>
int main()
{
float a, b, c, s, area, perimeter;
printf(“Enter the value of a, b, c: “);
scanf("%f %f %f", &a, &b, &c);
s = (a+b+c) / 2;
area = sqrt (s * (s-a) * (s-b) * (s-c));
perimeter = a + b + c;
printf("area = %.2f", area);
printf(“perimeter = %.2f”, perimeter);
return 0;
}

3. Area & Perimeter of a Rectangle: (10)


#include<stdio.h>
int main()
{
floatl, w, area, perimeter;
printf("Enter the Length&Width of Rectangle : ");
scanf("%f %f", &l, &w);
area = l * w;
perimeter = 2 * (l+w);
printf("Area of Rectangle : %.2f", area);
printf("Perimeter of Rectangle : %.2f", perimeter);
return (0);
}

THEOVE46MANIA 2
4. Convert Fahrenheit to Celsius: (17, 15, 10, 07)
#include <stdio.h>
int main()
{
float F, C;
printf("Enter the Temperature in Fahrenheit: ");
scanf("%f", &F);
C = (F-32) * 5/9;
printf("%2f F=%2f C", F,C);
return 0;
}

***C/5=(F-32)/9;
***F=(C*9/5)+32;

5. Multiplication Table of up to 5: (10)


#include <stdio.h>
int main()
{
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for(i=1; i<=5; ++i)
{
printf("%d * %d = %d \n", n, i, n*i);
}
return 0;
}

6. Even-Odd: (13)
#include <stdio.h>
int main()
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
if(n%2==0)
printf("Even number", n);
else
printf("Odd number", n);

return 0;
}

THEOVE46MANIA 3
7. Leap Year: (14)
#include <stdio.h>
int main()
{
int year;
printf(“Enter the Year: “);
scanf("%d", &year);
if((year%400)==0)
printf("Leap Year", year);
else if((year%100)!=0 && year%4==0)
printf("Leap Year", year);
else
printf("Not Leap Year", year);
return 0;
}

8. Sum of the Series: 1 + 1/2 + 1/3 +…..+1/n: (14)


#include <stdio.h>
int main()
{
float n, i, sum = 0;
printf("Enter the value of n: ");
scanf("%f", &n);
for(i=1; i<= n; i++)
{
sum = sum + 1/i;
}
printf("The Sum is %.2f",sum);
return 0;
}

9. Find the number & sum of all integers 50<i<800 & divisible by 9:
#include <stdio.h> (11, 08, 07)
int main()
{
int s=0, i;
for(i=51; i<800; i++)
{
if(i%9==0)
printf("\n%d", i);
}
s = s + i;
printf("\n sum is: %d", s);
return 0;
}

THEOVE46MANIA 4
10. Largest among three numbers (using Nested if…else): (15)
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter three numbers: \n");
scanf("%d %d %d", &a, &b, &c);
if(a>b)
{
if(a>c)
{
printf("%d is largest", a);
}
else
{
printf("%d is largest", c);
}
}
else
{
if(b>c)
{
printf("%d is largest", b);
}
else
{
printf("%d is largest", c);
}
}
return 0;
}

11. Display integer and floating point separately:


#include <stdio.h>
int main()
{
float a;
int b;
printf(“Enter the floating point number: “);
scanf("%f", &a);
b=a; // don’t use a=b //
printf("\nInteger part is %d", b);
printf("\nFloating part is %f", a-b);
return 0;
}

12. Grade of Marks: (16, 13, 06)


#include <stdio.h>
int main()
{

THEOVE46MANIA 5
int marks;
printf("Enter marks: ");
scanf("%d", &marks);
if(marks>=80)
{
printf("A+");
}
else if(marks>=70)
{
printf("A");
}
else if(marks>=60)
{
printf("A-");
}
else if(marks>=50)
{
printf("B");
}
else if(marks>=40)
{
printf("C");
}
else
{
printf("F");
}
return 0;
}

13. Palindrome: (14, 12, 11)


#include <stdio.h>
#include <string.h>
int main()
{
char c1[50], c2[50];
int l, i, k;
printf("Enter the String: ");
gets(c1);
l = strlen(c1);
for(i=0; i<l; i++)
{
c2[i]=c1[l-i-1];
}
c2[i]='\0';
k = strcmp(c1,c2);
if(k==0)
printf("\nThis is Palindrome");
else
printf("\nThis is not Palindrome");
return 0;

THEOVE46MANIA 6
}
14. Fibonacci Series: (18, 16, 13, 12, 09)
#include <stdio.h>
int main()
{
int x=0, y=1, z, n, i;
printf("How many numbers you want: ");
scanf("%d", &n);
printf("The Fibonacci Numbers: \n");
printf("0 1 ");
for (i=1; i<n-1; i++)
{
printf("%d ", x+y);
z = y;
y = x + y;
x = z;
}
return 0;
}

15. First 20th number Fibonacci Series: (11)


#include <stdio.h>
int main()
{
int x=0, y=1, z, i;
printf("The Fibonacci Numbers: \n");
printf("0 1 ");
for (i=1; i<19-1; i++)
{
printf("%d ", x+y);
z = y;
y = x + y;
x = z;
}
return 0;
}

16. Prime number or not:


#include <stdio.h>
int main()
{
int n, i, p=1;
printf(“Enter the number: “):
scanf("%d", &n);
for(i=2; i<=n/2; i++)
{
if(n%i==0)
{
p=0;
break;

THEOVE46MANIA 7
}
}
if(p==1)
printf("prime");
else
printf("not prime");
return 0;
}
17. Root of a Quardic Equation: (15, 10, 09, 06)
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, c;
float d, x1, x2;
printf("Enter the Value of a, b, c: ");
scanf("%d %d %d", &a, &b, &c);

d=(b*b) - (4*a*c);

if(a == 0)
{
x1 = x2 = -c / b;
printf("Roots are equal\n");
printf("Real roots are: %.2f and %.2f", x1, x2);
}
else if(d > 0)
{
x1 = (-b + sqrt(d)) / (2*a);
x2 = (-b - sqrt(d)) / (2*a);
printf("Roots are equal\n");
printf("Real roots are: %.2f and %.2f", x1, x2);
}
else
{
printf("No Real Roots");
}
return 0;
}
18. Swap/Interchange the value using Bitwise operator: (12)
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two integers: \n");
scanf("%d %d", &a, &b);
printf("Before swapping \n a=%d \n b=%d \n\n", a, b);
a = a^b;
b = b^a;
a = a^b; //using 3 times//

THEOVE46MANIA 8
printf("After swapping \n a=%d \n b=%d", a, b);
return 0;
}
19. Calculate the Factorial of a number using Recursion Function:
#include <stdio.h> (16, 13, 10, 09, 06)
int factor(int n)
{
if(n<=1)
return 1;
else
return(n*factor(n-1));
}
int main()
{
int n, factorial;
printf("Enter a number to find a factorial: ");
scanf("%d", &n);
factorial = factor(n);
printf("Factorial is: %d", factorial);
return 0;
}

20. Using Pointer to compute the sum of all elements stored in an Array
#include <stdio.h>
int main()
{
int *p, a[20], n, i, sum=0;
p=a;
printf("How many data you enter: ");
scanf("%d", &n);
i = 0;
while(i<n)
{
scanf("%d", &*(p+i));
i++;
}
for(i=0; i<=n; i++)
{
sum = sum + *(p+i);
}
printf("%d", sum);
return 0;
}

21. Calculate Sum & Avg using Array. (15)


#include <stdio.h>
int main()
{
int n, i;
float sum=0, Arr[100];

THEOVE46MANIA 9
printf("Enter the number of elements: ");
scanf("%d", &n);

for (i=0; i<n; i++)


{
printf("Enter element %d: ", i + 1);
scanf("%f", &Arr[i]);
sum = sum + Arr[i];
}
printf("\nThe sum of the array is : %0.2f", sum);
printf("\nThe average of the array is : %0.2f", sum / n);
return 0;
}
22. Sum of the digits of a given integer number. (09, 08)
#include <stdio.h>
int main()
{
int a, t, r, sum=0;
printf("Enter the number: ");
scanf("%d", &a);
t = a;
while (a > 0)
{
r = a % 10;
sum = sum + r;
a /= 10;
}
printf("Given number = %d\n", t);
printf("Sum of the digits %d = %d\n", t, sum);
return 0;
}

23. Diagonal elements of a 2D array to 1 and others to 0. (07, 06)


#include<stdio.h>
int main()
{

int a[10][10], i, j;
for(i=0; i<=6; i++)
{
for(j=0; j<=6; j++)
{
if(i==j || i+j==6)
printf("1 ");
else
printf("0 ");
}
printf("\n\n");
}
return 0;
}
THEOVE46MANIA 10
1. Record Student information according to their merit position. (17, 11, 08)
2. Write integer from 1 to 10 and store data into the file name “razu.dat” (17, 08)
3. Find out the GCD (Greatest Common Divisor) of two given integer a, b where
1<a, b<108. (16)
4. Read data from keyboard, write data to file named INPUT. Again, read data
from the file named INPUT and display it on screen. (16, 15, 12)
5. Evaluate the function sinx as defined by the infinite series of expansion. (15)
6. A Recursive function in C to compute value of xn where n is a positive integer
and x has a real value. (15)

7. Using pointer to read in an Array of integer and print it in reverse order. (14)
8. A file named DATA contains some integers number. Write a file C program
which will produce all odd numbers in a file named ODD and all even numbers in
a file named EVEN. (11, 10, 07)
9. Set all the diagonal elements of a two-dimensional array 1 and others to 0. (7,6)
10. Extract a portion of a character string and print the extracted string. Assume
that in characters are extracted, started with nth character. (11)

11. Takes an Integer as input and display it in Reverse Order. (18)

THEOVE46MANIA 11
Assalamu Alaikum.

I did my job. Now it’s your turn.


Please update this document, add more questions for our next
batches.
Thank you.
Md. Ohiduzzaman Ove
Dhaka City College
20th batch

THEOVE46MANIA 12

Вам также может понравиться