0% found this document useful (0 votes)
18 views10 pages

Addition of Two Numbers in C

The document contains C++ programs to perform basic mathematical operations and check character properties. It includes programs to add, subtract, and multiply two numbers. Other programs calculate the cube of a number, check if a character is an alphabet, digit or alphanumeric, and calculate the power of a number. The programs utilize functions to modularize the code and perform input, output and calculations.

Uploaded by

Kashif Mahmood
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

Addition of Two Numbers in C

The document contains C++ programs to perform basic mathematical operations and check character properties. It includes programs to add, subtract, and multiply two numbers. Other programs calculate the cube of a number, check if a character is an alphabet, digit or alphanumeric, and calculate the power of a number. The programs utilize functions to modularize the code and perform input, output and calculations.

Uploaded by

Kashif Mahmood
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C.

P LAB-01
Q#1:
Addition of two numbers:

#include<conio.h >
#include<iostream.h >
int input(void);
void output(int z);
int add(int x,int y);
int main()
{
int a,b,c;
clrscr();
a=input();
b=input();
c=add(a,b);
output(c);
getch();
return 0;
}
int input(void)
{
int v;
cout<<"\n enter value =";
cin>>v;
return v;
}
int add(int x,int y)
{
return(x+y);
}
void output(int z)
{
cout<<"\n result is ="<<z;

}
Q#2:
Subtraction of two numbers:

#include<conio.h >
#include<iostream.h >
int input(void);
void output(int z);
int sub(int x,int y);
int main()
{
int a,b,c;
clrscr();
a=input();
b=input();
c=sub(a,b);
output(c);
getch();
return 0;
}
int input(void)
{
int v;
cout<<"\n enter value =";
cin>>v;
return v;
}
int sub(int x,int y)
return(x-y);

void output(int z)
{
cout<<"\n result is ="<<z;

}
Q#3:
Multiplication of two numbers:

#include<conio.h >
#include<iostream.h >
int input(void);
void output(int z);
int sub(int x,int y);
int main()
{
int a,b,c;
clrscr();
a=input();
b=input();
c=sub(a,b);
output(c);
getch();
return 0;
}
int input(void)
{
int v;
cout<<"\n enter value =";
cin>>v;
return v;
}
int sub(int x,int y)
{
return(x-y);
}
void output(int z)
{
cout<<"\n result is ="<<z;

}
C.P LAB-02

Q#1:
To calculate Cube of a number:

#include<conio.h >
#include<iostream.h >

int cube(void);

int main()
{
clrscr();
int x;
x=cube();

cout<<"\n cube="<<x;
getch();
return 0;
}
int cube(void)
{
int cube;
int a;
cout<<"\n enterr num";
cin>>a;
cube=a*a*a;

}
Q#2:
To calculate Cube of numbers:

#include<conio.h >
#include<iostream.h >
int input(void);
void output(int z);
int mul(int x,int y);
int main()
{
int a,b,c;
clrscr();
a=input();
b=input();
c=mul(a,b);
output(c);
getch();
return 0;
}
int input(void)
{
int v;
cout<<"\n enter value =";
cin>>v;
return v;
}
int mul(int x,int y)
{
return(x*y);
}
void output(int z)
{
cout<<"\n result is ="<<z;

}
Q#3:
To calculate power:

#include<conio.h >
#include<iostream.h >

void cube(void) ;

int main()
{
cube();
getch();
return 0;
}
void cube(void)
{
int n,cu;
cout<<"\n enter num";
cin>>n;
cu=n*n*n;
cout<<"\n cube is="<<cu;
}

Q#4:
To calculate power:

#include<conio.h >
#include<iostream.h >

void cube(int a);

int main()
{
clrscr();
int x;
cout<<"\n enter value=";
cin>>x;

cube(x);
getch();
return 0;
}
void cube(int a)
{
int cube;
cube=a*a*a;
cout<<"\n cube is="<<cube;
}
C.P LAB-03

Q#1:
To check char is alphabet or digit:

#include<conio.h >
#include<ctype.h>
#include<iostream.h>
int main(void)
{
clrscr();
char ch;
cout<<"\n";
cin>>ch;
cout<<isalpha(ch);
if(isalpha(ch))
{
cout<<"\n char is alphabet or digit";
}
else
{
cout<<"\n char is not alphabet or digit";
}
getch();
return 0;
Q#2:
To check Ascii Values:

#include<conio.h >
#include<ctype.h>
#include<iostream.h>
int main(void)
{
clrscr();
char ch;
cout<<"\n";
cin>>ch;
cout<<isascii(ch);
if(isascii(ch))
{
cout<<"\n char is alphabet or digit";
}
else
{
cout<<"\n char is not alphabet or digit";
}
getch();
return 0;
}

Q#3:
TO check char is alphabet or Number:

#include<conio.h >
#include<ctype.h>
#include<iostream.h>
int main(void)
{
clrscr();
char ch;
cout<<"\n";
cin>>ch;
cout<<isalnum(ch);
if(isalnum(ch))
{
cout<<"\n char is alphabet or digit";
}
else
{
cout<<"\n char is not alphabet or digit";
}
getch();
return 0;
Q#4:
TO check char is alphabet or Digit:

#include<conio.h >
#include<ctype.h>
#include<iostream.h>
int main(void)
{
clrscr();
char ch;
cout<<"\n";
cin>>ch;
cout<<isdigit(ch);
if(isdigit(ch))
{
cout<<"\n char is alphabet or digit";
}
else
{
cout<<"\n char is not alphabet or digit";
}
getch();
return 0;
}

Q#4:
TO check char is alphabet Number:

#include<conio.h >
#include<ctype.h>
#include<iostream.h>
int main(void)
{
clrscr();
char ch;
cout<<"\n";
cin>>ch;
cout<<isalnum(ch);
if(isalnum(ch))
{
cout<<"\n char is alphabet or digit";
}
else
{
cout<<"\n char is not alphabet or digit";
}
getch();
return 0;
}

You might also like