Professional Documents
Culture Documents
#include <stdio.h>
int main()
{ int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
return 0;
}
void main( )
{
int x, y;
x = 15;
y = 18;
if (x > y )
{
printf("x is greater than y");
}
else
{
printf("y is greater than x");
}
}
4 Decision making and looping statements
#include <stdio.h>
int main()
{
int i;
5 Array ;
#include <stdio.h>
int main() {
int values[5];
printf("Enter 5 integers: ");
for(int i = 0; i < 5; ++i) {
scanf("%d", &values[i]);
}
#include <stdio.h>
int addNumbers(int a, int b);
int main()
{
int n1,n2,sum;
return 0;
}
c = 22;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 22
pc = &c;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 22
c = 11;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 11
*pc = 2;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 2
return 0;
}
FILE
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE *fptr;
if ((fptr =
fopen("C:\\program.txt","r")) == NULL){
printf("Error! opening file");
exit(1);
}
fscanf(fptr,"%d", &num);
return 0;
}
Output
12
C++ program to demonstrate
inheritance
#include <iostream>
using namespace std;
// base class
class Animal {
public:
void eat() {
cout << "I can eat!" << endl;
}
void sleep() {
cout << "I can sleep!" << endl;
}
};
// derived class
class Dog : public Animal {
public:
void bark() {
cout << "I can bark! Woof woof!!" << endl;
}
};
int main() {
// Create object of the Dog class
Dog dog1;
// Calling members of the base class
dog1.eat();
dog1.sleep();
return 0;
}
UNION
#include <stdio.h>
union unionJob
{
char name[32];
float salary;
int workerNo;
union Job;
};
struct structJob
{
char name[32];
float salary;
int workerNo;
struct job;
};
int main()
{
printf("size of union=%sbytes","size of (union job)");
printf("\nsize of struct=%sbytes","size of (struct
job)");
return 0;
}
class Demo {
private:
cout<<"Inside Constructor"<<endl;
num1 = n1;
num2 = n2;
void display() {
~Demo() {
cout<<"Inside Destructor";
};
int main() {
obj1.display();
return 0;
}
9 th program - file handling
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
FILE *fptr;
if ((fptr =
fopen("C:\\program.txt","r")) == NULL){
printf("Error! opening file");
exit(1);
}
fscanf(fptr,"%d", &num);
return 0;
}