2. Question:-
Write a program that represents
Switch case, also add function in
each case.
#include<stdio.h>
int result;
int add(int a, int b);
int subtract(int a, int b);
int multi(int a, int b);
int main() {
int x, y, choice;
printf("tEnter two number: ");
scanf("%d%d", &x, &y);
printf("n");
printf("tAddition. [1]n");
printf("tSubtraction .[2]n");
printf("tMultiplication.[3]nn");
3. switch(choice) {
case 1:
printf("tTotal is %dn", add(x, y)); break;
case 2: printf("tSubtraction is %dn", subtract(x, y));
break;
case 3:
printf("tMultiplication is %dn", multi(x, y));
break;
default:
printf("tYou entered wrong number!!n");
break; } }
int add(int a, int b) { result = a + b; return result; }
int subtract(int a, int b) { result = a - b; return result; }
int multi(int a, int b) { result = a * b; return result; }
7. This program takes a positive integer
from user and stores it in variable n.Then,
for loop is executed which checks whether
the number entered by user is perfectly
divisible by i or not starting with initial
value of i equals to 2 and increasing the
value of i in each iteration.
If the number entered by user is perfectly
divisible by i then, flag is set to 1
and that number will not be a prime
number but, if the number is not perfectly
divisible by i until test condition i<=n/2 is
true means,
it is only divisible by 1 and that number
itself and that number is a prime number.
Code description:
8. #include <stdio.h>
int main()
{
double divi = 1, h = 0, sum = 0;
double str[100];
int i = 0, j = 0, r, value;
printf("Division multiple
integers.nnn");
printf("Enter the number of value = ");
scanf("%d", &value);
printf("nn");
Question:-
How to divide multiple
integers
Code:
9. for (j = 0; j < 1; j++){
printf("enter %d%s value = ", j + 1, (j + 1 == 1) ? "st": (j + 1 == 2) ?
"nd": (j + 1 == 3) ? "rd": " ");
scanf("%lf", &str[j]);
divi = str[j] / divi;
printf("%.2lfn", divi); }
for (i = 1; i < value; i++){
printf("enter %d%s value = ", i + 1, (i + 1 == 1) ? "st": (i + 1 == 2) ?
"nd": (i + 1 == 3) ? "rd": "th");
scanf("%lf", &str[i]);
divi = divi / str[i];
printf("%lfn", divi);}
getch();return 0;}
10. At first I use “stdio” header file, I use
double data type and integer data type.
now firstly the program want the number
of value from the user that can be 5, 6, 7
and even more now the first for loop will
get the first value from the user then the
program put the value into "divi" that's
because it can divide with the next value.
Now the second "for" loop will get the
second value from user from the user and
divide from the first value then the
program do the same thing till the number
of value that is given by the user. and al last
it will show the result to the user. then
terminated.
Code Description:
11.
12. #include <stdio.h>
int main(){
int qsn1, qsn2, qsn3, qsn4, qsn5, qsn6;
printf ("1. What is the capital of Bangladesh?nn1.
Dhakan2. Chittagongn3. Khulna");
printf("nEnter answer : ");
scanf("%d", &qsn1);
printf ("2. What is the best mobile company?nn1.
Symphonyn2. Blackberryn3. Apple");
printf("nEnter answer : ");
scanf("%d", &qsn2);
printf ("3. Where is Bangladesh situated?nn1. Asian2.
African3. America");
printf("nEnter answer : ");
scanf("%d", &qsn3);
printf ("4. What is the capital of England?nn1.
Dhakan2. Londonn3. Khulna");
printf("nEnter answer : ");
scanf("%d", &qsn4);
Question:-
A program that can check the
given MCQ’s from the user.
13. printf (“5. What is the capital of Japan?nn1. Dhakan2.
Londonn3. Tokyo");
printf("nEnter answer : ");
scanf("%d", &qsn5);
printf("nn");
if (qsn1 == 1){
printf("1. Truen");
}else if (qsn1 == 3 || qsn1 == 2){
printf("1. Falsen");
}
if (qsn2 == 3){
printf("2. Truen");
}else if (qsn2 == 1 || qsn2 == 2){
printf("2. False.n");
}
if (qsn3 == 1){
printf("3. Truen");
}else if (qsn3 == 3 || qsn3 == 2){
printf("3. False.n");
}