C Programming Solve: 1. Syntax Errors: 2. Semantic Errors
C Programming Solve: 1. Syntax Errors: 2. Semantic Errors
Compiler Interpreter
1.Compiler takes enter program as input 1.Interpreter takes enter program as input.
C++
#include <iostream>
using namespace std;
class Cal {
public:
int add(int a,int b){
return a + b;
}
int add(int a, int b, int c)
{
return a + b + c;
}
};
int main(void) {
Cal C; // class object declaration.
cout<<C.add(10, 20)<<endl;
cout<<C.add(12, 20, 23);
return 0;
}
C++
#include <iostream>
using namespace std;
class Test
{
public:
int num;
Test(int x){
num =x;
}
void operator ++() {
num = num+2;
}
void Print() {
cout<<"The Count is: "<<num;
}
};
int main()
{
Test tt(8);
++tt; // calling of a function "void operator ++()"
tt.Print();
return 0;
}
Difference between i++ and ++i with example in summarize
Time of Increment:
Example:
C++
int i = 5;
Structure:
C
if (condition1) {
if (condition2) { // Nested if
} else {
} else {
Structures (struct)
Unions (union)
● Purpose: Allow different data types to share the same memory location,
but only one member can hold a value at a time.
////bhujar jonno
.#include <iostream>
using namespace std;
class base {
private:
int private_variable;
protected:
int protected_variable;
public:
base()
{
private_variable = 10;
protected_variable = 99;
}
// driver code
int main()
{
base object1;
friendFunction(object1);
return 0;
}
Page-4
5.c)programming language : A language that are used to communicate with
other computers.Several types of programming language that exist.
int main()
{
int n,sum=0;
printf("N = ");
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum = sum + i;
}
printf("summation = %d",sum);
○
○
1.b)Can I use int data type to store 32678 value? If not why? //////short
int hobe
No, you cannot use the standard int data type to store the value 32678.
Range of int: The typical range of the int data type on most systems is -32768
to 32767. This means it can only accommodate integers within this range. 32678
falls outside this range, so trying to store it in an int variable would lead to
unexpected behavior or errors.
Alternative Data Types:
Here's the table of data types in C with their ranges expressed in 2^power
notation:
unsigned 1 0 to 2^8 - 1
char
unsigned 2 0 to 2^16 - 1
short int
int main() {
int n;
}
int fact(int a){
if(a==0)
return 1;
else
return a*fact(a-1);
}
c)Define pointer.
Pointer:The pointer is a variable which stores the address of another
variable.Pointer reduces the code and improves the performance.We can
return multiple values from a function using the pointer.
///just understanding DMA সি প্রোগ্রামিং -২৬ঃ Pointer- Dynamic memory allocation,
malloc(), calloc(), free(), realloc() (youtube.com)
};
class JavaExample
{
display();
}
}
Page-8
5.or.b)1^2+2^2+3^2+4^2+5^2+.....................+N^2
Go to page 9 ( i repace by i*i)
6.Define function prototype.
In programming, a function prototype is a declaration of a function.
Key elements of a function prototype:
1. Return type: Declares the data type of the value the function will return
2. Function name: The identifier used to call the function.
3. Parameter list: It lists the names and data types of the arguments the function
expects to receive.
4. Optional modifiers: Some languages allow additional modifiers to specify
features
Example (C++):
Explanation:
● int: Return type
● addNumbers: Function name.
● (int a, int b): Parameter list,
Function overloading –go to page 2
1) Code Optimization
2) Ease of traversing
3) Ease of sorting:
4) Random Access
Declaration of C Array
1. data_type array_name[array_size];
Now, let us see the example to declare the array.
1. int marks[5];
void myFunction() {
int localVar = 10; // Local variable
printf("Inside function: localVar = %d\n", localVar);
}
int main() {
myFunction();
// printf("Inside main: localVar = %d\n", localVar); // Error: localVar is not
accessible here
return 0;
}
void myFunction() {
printf("Inside function: globalVar = %d\n", globalVar);
}
int main() {
printf("Inside main: globalVar = %d\n", globalVar);
myFunction();
return 0;
}
3.or.b) go to page 13
3.or.c)go to page 3
Page-9
7.Program in C language to find area and perimeter of circle
#include<stdio.h>
int main()
{
double r,area,Perimeter.;
printf("Enter radius : ");
scanf("%lf",&r);
area=3.1416*r*r;
Perimeter=2*3.1416*r;
printf("Area of the circle: %.2lf \n", area);
printf("Perimeter. of the circle: %.2lf units\n", Perimeter.);
}
int main(){
int i,n,count=0;
}
C programming Bangla Tutorial : Check Prime Number (youtube.com)
class Animal {
public:
void eat() {
std::cout << "Animal is eating." << std::endl;
}
};
int main() {
Dog dog;
dog.eat(); // Inherited from Animal
dog.bark(); // Specific to Dog
return 0;
}
C
#include <stdio.h>
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
int num1, num2;
return 0;
}
int
main()
{
float base, height, area;
return 0;
}
5.or.What do you mean by low level language? Write its advantages and
disadvantages
Low-Level Language:Assembly language uses symbolic to represent
various machine language instructions(ADD,SUB,MUL,DIV,INC). It has to
convert into machine language. Assembler convert assembly language to
machine language.
Advantages:
● Performance: They offer speed and efficiency
● Fine-grained control:we have greater control over hardware resources,
memory management, and optimizations.
● Portability: Some languages like assembly are relatively
machine-independent and can run on different platforms.
Disadvantages:
● Complexity: They are harder to learn and use
● Error-prone: The lack of built-in checks makes them to errors
● Readability and maintainability: Code can be less readable and harder
to maintain
Go to page - 9
Page-11
10.or .go to page 13 (datatype)
1.a.Flowchart:A graphical representation of an algorithm, using symbols and
connecting arrows. It visualizes the steps and logic of a process.
How many types of flowcharts and what are they? Write function with
diagram of program flowchart drawing symbols.
While there are many types of flowcharts, here are some of the most common
ones:
1. Process Flowchart:
2. Workflow Diagram:
3. Swimlane Flowchart:
4. Data Flow Diagram (DFD):
5. Program Flowchart:
Here's a simple example of a program flowchart using common symbols:
● Oval for Start
● Parallelogram for Input
● Rectangle for Process
● Diamond for Decision
● Parallelogram for Output
● Oval for End
● Arrows indicating flow direction]
1.or)Why is C Plus Plus called an improved version of C?
C++ is indeed considered an improved version of C for several reasons:
1. Object-Oriented Programming (OOP): C++ introduces object-oriented
features
2. Templates: C++ allows creating generic templates
3. Exception Handling: C++ handles errors with exception handling
mechanisms
4. Standard Template Library (STL): C++ boasts a rich Standard Template
Library (STL)
5. Memory Management: C++ offers both manual and automatic memory
management,
6. Inline Functions: C++ allows you to declare functions within other functions
7. Enhanced Syntax: C++ inherits the familiar syntax of C.
2.a)Program:A set of instruction that are used to solve a particular problem.
Go to page -18
2.b) Go to page -20
6.or) Go to page -8
Page-12
1.b) Go to page -18
1.c)Go to page -3
1.or.b)Go to page -24
2.c)Go to page -19
3.a)Go to page -15
4.b)Go to page -1
Page-13
10.or)Go to page -5
1st Generation 2nd Generation 3rd Generation 4th Generation 5th Generation
Education is Education is 2 2 2
very fast slow
compare 1st
generation
Slow Significant 2 2 2
performance performance
improvement
over the first
generation.
int main(){
int n,a,b,c;
Example:Go to page -6
Page-14
9.or)Go to page -15
1.c)find leap year using c program
The encapsulate class is easy to test. So, it is better for unit testing.
page-15
8.Go to page -6
1.a)Go to page -26
1.b)Go to page -17,20
define register variable
Register variables are a special type of variable in some programming
languages that are stored directly in the CPU's registers instead of in main
memory. This provides faster access and manipulation of their values.
● Declaration: They are declared using the register keyword before the
variable type in most languages that support them (e.g., register int
count;).
1.or.b.)Go to page -19
page-16
5.a.)Go to page -15
8)Go to page -7
1.b)Go to page -3
1.c)
Encapsulation:Binding (or wrapping) code and data together into a single
unit is known as encapsulation.
Go to 29
Page-17
5.or.b)Go to page -1
7)Go to page -5
2.a)Go to page -13
2.b)Go to page -6
2.or.a)Go to page -5
2.or.b)Explain the difference between recursion and recursive function
Recursion is a programming technique where a function calls itself directly or
indirectly, breaking down a problem into smaller subproblems. It's a powerful
approach for solving problems.
Recursive function is a function that employs recursion to solve a problem. It
has two essential components:
1. Base case(s): The simplest cases that can be solved directly without
further recursion. They act as the stopping points for the recursive calls.
2. Recursive case(s): The cases that break the problem down into smaller
versions of itself, calling the function recursively.
Key points to remember:
● Recursion itself is the concept of a function calling itself.
● A recursive function is a specific implementation of that concept,
designed to solve a problem using recursion.
Go to 14 page
Page-18
7.or) Go to page 9 ( i repace by i*i)
8) Go to page 22
Page-19
1) Go to page 1
7) Go to page 19
11)finds and prints even numbers from 1 to 50:
#include <stdio.h>
int main() {
int i;
return 0;
}
15.find the Fibonacci series
#include <stdio.h>
int main() {
int n, i, first = 0, second = 1, fibo;
return 0;
}
Page -20
20) print prime number
#include <stdio.h>
int main() {
int i, num, count;
printf("\n");
return 0;
}
12)Go to page 9
17)Go to page 27
Page-21
11)Go to page 13
14)Go to page 18
16)Go to page 22
10)Go to page 6
17)find summation of fibonacci series in c
#include <stdio.h>
int main() {
int n, i, first = 0, second = 1,sum=0, fibo;
return 0;
}
Page-22
1.or.a)Go to page 26
10.or.)Go to page 25
Page-23
1.or.a)Go to page 26
7.or)Go to page 9
1.or)Go to page 26
Page-24
or)Go to page 26
6)Go to page 9
9)Go to page 10,25
1.or)Go to page 26
Page-25
6).Go to page 25
5.or)Go to page 9
Page-26
6)Go to page 9
1)Go to page 26
4.a)Go to page 10,20,
Page-27
6)Go to page 25
c/////////////code/////////
7.#include <stdio.h>
int main() {
float C,F;
scanf("%f",&F);
C=((F-32)/9)*5;
printf("%f",C);
return 0;
}
8.#include <stdio.h>
int main() {
int a,b,c;
printf("Enter three numbers :");
scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c)
printf("%d is largest",a);
else if (b>=a && b>=c)
printf("%d is largest",b);
else
printf("%d is largest",c);
return 0;
}
10.#include <stdio.h>
int main() {
int i,n,sum=0;
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf("Summation = %d",sum);
return 0;
}
19.#include <stdio.h>
#include <math.h>
int main() {
int i,sum=0,n;
printf("Enter any number that you want to display for series:");
scanf("%d",&n);
for(i=1;i<=n;i=i+1){
sum=sum+pow(i,i);
}
printf("Summation = %d",sum);
return 0;
}
30.#include <stdio.h>
int main() {
int first =0,second=1,count=0,fibo,n;
printf("Enter the range of series :");
scanf("%d",&n);
while(count<n){
if(count<=1){
fibo = count;
}
else{
fibo = first + second;
first = second;
second = fibo;
}
printf(" %d ",fibo);
count++;
}
return 0;
}
33.#include <stdio.h>
int main() {
int n,count=0;
printf("Enter any numbers: ");
scanf("%d",&n);
for(int i =2;i<n;i++){
if(n%i==0){
count++;
break;
}
}
if(count==0){
printf("Prime");
}
else{
printf("Not prime");
}
return 0;
}
34.#include <stdio.h>
int main() {
int even_count = 0, odd_count = 0, num;
return 0;
}
35.#include <stdio.h>
int main() {
int num,positive=0,negative=0;
for(int i=1;i<=10;i++){
printf("Enter number %d:",i);
scanf("%d",&num);
if(num>0){
positive++;
}else{
negative++;
}
}
printf("positive = %d",positive);
printf("negative= %d",negative);
return 0;
}
36.#include <stdio.h>
#include <ctype.h>
int main() {
char xx;
printf("Enter any character:");
scanf("%c",&xx);
printf("Uppercase equivalent of %c is %c\n",xx,toupper(xx));
}
38.#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, discriminant, root1, root2;
// Calculate discriminant
discriminant = b * b - 4 * a * c;
// Calculate roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different:\n");
printf("Root 1 = %.2f\n", root1);
printf("Root 2 = %.2f\n", root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Roots are real and same:\n");
printf("Root 1 = Root 2 = %.2f\n", root1);
} else {
return 0;
}
20) print prime number
#include <stdio.h>
int main() {
int i, num, count;
printf("\n");
return 0;
}