0% found this document useful (0 votes)
20 views76 pages

Ppa Programs

Uploaded by

xyjoker389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views76 pages

Ppa Programs

Uploaded by

xyjoker389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

1. Program to print ‘hello’.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr( );
printf(“hello”);
getch();
}
2.Program to addition of two integer numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=2;
int b=4;
int add;
add=a+b;
printf(“the result is=%d”,add);
getch();
}
3.Program to subtraction of two integer numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=7;
int b=4;
int sub;
sub=a-b;
printf(“the result is=%d”,sub);
getch();
}
4.Program to multiplication of two integer numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=3;
int b=4;
int mul;
printf(“the result is=%d”,mul);
getch();
}
5.Program to division of two integer numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=6;
int b=3;
int div;
printf(“the result is=%d”,div);
getch();
}
6.Program to find the area of triangle.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a;
int b;
int c;
int s;
int area;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
printf(“enter the value of c\n”);
scanf(“%d”,&c);
s=a+b+c/2;
area=sqrt[s*(s-a)*(s-b)*(s-c)];
printf(“the area is=%d”,area);
getch();
}
7. Program to find the area of circle.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float r;
float pie=3.14;
float area;
printf(“enter the radius\n”);
scanf(“%f”,&r”);
area=pie*r*r;
printf(“the area is=%f”,area);
getch();
}
8. Program to find the area of square.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int side;
int area;
printf(“enter the value of side\n”);
scanf(“%d”,&side);
area=side*side;
printf(“the area is=%d”,area);
getch();
}
9. Program to find the area of rectangle.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int l;
int b;
int area;
printf(“enter the value of length\n”);
scanf(“%d”,&l);
printf(“enter the value of breath\n”);
scanf(“%d”,&b);
area=l*b;
printf(“the area is=%d”,area);
getch();
}
10. Program of swapping by 2 variables.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
printf(“before swapping\n”);
printf(“the value of a is %d\n”,a);
printf(“the value of b is %d\n”,b);
a=a+b;
b=a-b;
a=a-b;
printf(“after swapping”);
printf(“the value of a is %d\n”,a);
printf(“the value of b is %d\n”,b);
getch();
}
11. Program of swapping by 3 variables.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int temp;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
printf(“before swapping\n”);
printf(“the value of a is %d\n”,a);
printf(“the value of b is %d\n”,b);
a=b;
b=temp;
temp=a;
printf(“after swapping\n”);
printf(“the value of a is %d\n”,a);
printf(“the value of b is %d\n”,b);
getch();
}
12. Program to enter and print a character by
unformatted input and output statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char letter;
printf(“enter the character\n”);
letter=getchar;
printf(“the character is”);
putchar(letter);
getch();
}
13. Program to enter the string by unformatted input
and output statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char city[20];
printf(“enter the name of city\n”);
gets(city);
printf(“the city name is”);
puts(city);
getch();
}
14. Program to convert temprature fahrenheit to
celcius.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float far;
float cel;
printf(“enter the temprature in fahrenheit\n”);
scanf(“%f”,&far);
cel=5*far-32/9;
printf(“celcius=%f”,cel);
getch();
}
15. Program to convert temprature celcius to
fahrenheit.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float cel;
float far;
printf(“enter the temprature in celcuis\n”);
scanf(“%f”,&cel);
far=cel*9/5+32;
printf(“fahrenheit=%f”,far);
getch();
}
16. Program to ckeck the number is even by if
statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
printf(“enter the number\n”);
scanf(“%d”,&a);
if(a%2==0)
{
printf(“number is even\n”);
}
getch();
}
17. Program to check the number is positive by if
statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
printf(“enter the number\n”);
scanf(“%d”,&a);
if(a>0)
{
printf(“number is positive\n”);
}
getch();
}
18. Program to check the number is even or odd by if-
else statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
if(a%2==0)
{
printf(“a is even”);
}
else
{
printf(“a is odd”);
}
getch();
}
19. Program to check the number is positive or
negative by if- else statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
if(a>0)
{
printf(“a is positive”);
}
else
{
printf(“a is negative”);
}
getch();
}
20. Program to find the largest number between two
numbers by if-else statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
if(a>b)
{
printf(“a is larger than b”);
}
else
{
printf(“b is greater than a”);
}
getch();
}
21. Program to find the largest between three numbers
by nested if statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int c;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
printf(“enter the value of c\n”);
scanf(“%d”,&c);
if(a>b)
{
if(a>c)
{
printf(“a is largest”);
}
else
{
printf(“c is largest”);
}
}
else if(b>c)
{
printf(“b is largest”);
}
else
{
printf(“c is largest”);
}
getch();
}
22. Program to make a calculator by switch statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float a;
float b;
float c;
float s;
float r;
float pie=3.14;
float result;
int n;
int choice;
printf(“press 1 for addition\n”);
printf(“press 2 for subtraction\n”);
printf(“press 3 for multiplication\n”);
printf(“press 4 for division\n”);
printf(“press 5 for area of square\n”);
printf(“press 6 for area of rectangle\n”);
printf(“press 7 for area of triangle\n”);
printf(“press 8 for area of circle\n”);
printf(“press 9 for value check odd or even\n”);
printf(“press 10 for value check positive or negative\n”);
printf(“enter your choice”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
printf(“enter the value of a\n”);
scanf(“%f”,&a);
printf(“enter the value of b\n”);
scanf(“%f”,&b);
result=a+b;
printf(“the result is=%f”,result);
break;
case 2:
printf(“enter the value of a\n”);
scanf(“%f”,&a);
printf(“enter the value of b\n”);
scanf(“%f”,&b);
result=a-b;
printf(“the result is =%f”,result);
break;
case 3:
printf(“enter the value of a\n”);
scanf(“%f”,&a);
printf(“enter the value of b\n”);
scanf(“%f”,&b);
result=a*b;
printf(“the result is =%f”,result);
break;
case 4:
printf(“enter the value of a\n”);
scanf(“%f”,&a);
printf(“enter the value of b\n”);
scanf(“%f”,&b);
result=a/b;
printf(“the result is =%f”,result);
break;
case 5:
printf(“enter the value of side\n”);
scanf(“%f”,&a);
result=side*side;
printf(“the area is=%f”,result);
break;
case 6:
printf(“enter the value of length\n”);
scanf(“%f”,&a);
printf(“enter the value of breath\n”);
scanf(“%f”,&b);
result=a*b;
printf(“the area is =%f”,result);
break;
case 7:
printf(“enter the value of a\n”);
scanf(“%f”,&a);
printf(“enter the value of b\n”);
scanf(“%f”,&b);
printf(“enter the value of c\n”);
scanf(“%f”,&c);
s=a+b+c/2;
result=sqrt[s*(s-a)*(s-b)*(s-c)];
printf(“the area is=%f”,result);
break;
case 8:
printf(“enter the radius\n”);
scanf(“%f”,&r”);
result=pie*r*r;
printf(“the area is=%f”,result)
break;
case 9:
printf(“enter the value of a\n”);
scanf(“%d”,&n);
if(a%2==0)
{
printf(“a is even”);
}
else
{
printf(“a is odd”);
}
break;
case 10:
printf(“enter the value of a\n”);
scanf(“%d”,&n);
if(a>0)
{
printf(“a is positive”);
}
else
{
printf(“a is negative”);
}
break;
default:
printf(“your choice is invalid\n”);
}
getch();
}
23. Program to print ‘hello’ n times by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the value of n\n”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
printf(“hello”);
i++;
}
getch();
}
24. Program to calculate the sum of first five integer
numbers by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
sum=0;
i=1;
while(i<=5)
{
sum=sum+i;
i++;
}
printf(“sum=%d”,sum);
getch();
}
25. Program to calculate the sum of first n integer
numbers by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
sum=0;
printf(“enter the value of n\n”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
printf(“sum=%d”,sum);
getch();
}
26. Program to print a table by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
int m;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
while(i<=10)
{
m=n*i;
printf(“%d*%d=%d”,n,i,m);
i++;
}
getch();
}
27. Program to print counting by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
while(i<=5)
{
printf(“%d”,i);
i++;
}
getch();
}
28. Program to ptint even series by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=2;
while(i<=n)
{
printf(“%d”,i);
i=i+2;
}
getch();
}
29. Program to print odd series by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
while(i<=n)
{
printf(“%d”,i);
i=i+2;
}
getch();
}
30. Program of checking the prime number by while
loop.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=2;
while(i<=n-1)
{
if(n%1==0)
{
printf(“number is not prime\n”);
break;
}
i++;
}
if(n==i)
{
printf(“number is prime\n”);
}
getch();
}
31. Program to reverse the number by while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int digit;
int rev=0;
printf(“enter the number\n”);
scanf(“%d”,&n);
while(n>0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
printf(“%d”,rev);
getch();
}
32. Program to checking the pelendrom number by
while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int digit;
int rev=0;
int original;
printf(“enter the number\n”);
scanf(“%d”,&n);
original=n;
while(n>o)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
printf(“original number=%d\n”,original);
printf(“reverse of number=%d”,rev);
if(rev==original)
{
printf(“number is palindrom\n”);
}
else
{
printf(“number is not palindrom\n”);
}
getch(); }
33. Program to print a table by do-while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
int m;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
do
{
m=n*i;
printf(“%d*%d=%d”,n,i,m);
i++;
}
while(i<=10);
getch();
}
34. Program to print counting by do-while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
do
{
printf(“%d”,i);
i++;
}
while(i<=5);
getch();
}
35. Program to print odd series by do-while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=1;
do
{
printf(“%d”,i);
i=i+2;
}
while(i<=n);
getch();
}
36. Program to print even series by do-while loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
i=2;
do
{
printf(“%d”,i);
i=i+2;
}
while(i<=n);
getch();
}
37. Program to print ‘hello’ n times by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the value of n\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
printf(“hello”);
}
getch();
}
38. Program to print counting by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the total number to count\n”);
scanf(“%d”,&n);
for(i=1; i<=10; i++)
{
printf(“%d”,i);
}
getch();
}
39. Program to print table by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
int m;
printf(“enter the number\n”);
scanf(“%d”,&n);
for(i=1; i<=10; i++)
{
m=n*i;
printf(“%d*%d=%d”,n,i,m);
}
getch();
}
40. Program to print the even series by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
for(i=2; i<=n; i++)
{
printf(“%d”,i);
i=i+2;
}
getch();
}
41. Program to print odd series by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter te number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
printf(“%d”,i);
i=i+2;
}
getch();
}
42. Program of checking the prime number by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int n;
printf(“enter the number\n”);
scanf(“%d”,&n);
for(i=2; i<=n-1; i++)
{
if(n%1==0)
{
printf(“number is not prime\n”);
break;
}
}
if(n==i)
{
printf(“number is prime\n”);
}
getch();
}
43. Program to print fabonacci series by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int fib 1=0;
int fib 2=1;
int fib 3;
printf(“how many numbers in series\n”);
scanf(“%d”,&n);
printf(“fabonacci series\n”);
printf(“%d”,fib 1);
printf(“%d”,fib 2);
for(i=3; i<=n; i++)
{
fib 3=fib 1+fib 2;
printf(“%d”,fib 3);
fib 1=fib 2;
fib 2=fib 3;
}
getch();
}
44. Program to find the factorial by for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
long int i;
long int fact=1;
long int n;
printf(“enter the number\n”);
scanf(“%ld”,&n);
if(n==0)
{
printf(“factorial=%ld”,fact);
}
else
{
for(i=1; i<=n; i++)
{
fact=fact*1;
}
printf(“factorial=%ld”,fact);
}
getch();
}
45. Program to print right angled pascal triangle by
nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int j;
int n;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf(“* ”);
}
printf(“\n”);
}
getch();
}
46. Program to print an invert right angled pascal
triangle by nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=n; i>=1; i--)
{
for(j=i; j>=1; j--)
{
printf(“ *”);
}
printf(“\n”);
}
getch();
}
47. Program to print left angled pascal triangle by
nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“ *”);
}
printf(“\n”);
}
getch();
}
48. Program to print an inverted left angled pascal
triangle by nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum value\n”);
scanf(“%d”,&n);
for(i=n; i>=1; i--)
{
for(j=n; j>=i; j--)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“ *”);
}
printf(“\n”);
}
getch();
}
49. Program to print side pyramid of number by
nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“%d”,k);
}
printf(“\n”);
}
for(i=n; i>=1; i--)
{
for(j=n; j>=i; j--)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“%d”,k);
}
printf(“\n”);
}
getch();
}
50. Program to print side pyramid of numder by
nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf(“%d”,i);
}
printf(“\n”);
}
for(i=n; i>=1; i--)
{
for(j=i; j>=1; j--)
{
printf(“%d”,i);
}
printf(“\n”);
}
getch();
}
51. Program to print pascal pyramid by nested-for
loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf(“ ”);
}
for(k=1; k<=2*i-1; k++)
{
printf(“ *”);
}
printf(“\n”);
}
getch();
}
52. Program to print an inverted pascal pyramid by
nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=n; i>=1; i--)
{
for(j=n; j>=i; j--)
{
printf(“ ”);
}
for(k=1; k<=2*i-1; k++)
{
printf(“ *”);
}
printf(“\n”);
}
getch();
}
53. Program to print side pyramid of lower-case
alphabet by nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
int k;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“%c”,’a’+k);
}
printf(“\n”);
}
for(i=n; i>=1; i--)
{
for(j=n; j>=i; j--)
{
printf(“ ”);
}
for(k=1; k<=i; k++)
{
printf(“%c”,’a’+k);
}
printf(“\n”);
}
getch();
}
54. Program to print side pyramid of upper case
alphabet by nested-for loop.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int i;
int j;
printf(“enter the maximum number\n”);
scanf(“%d”,&n);
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf(“%c”,’A’+i);
}
printf(“\n”);
}
for(i=n; i>=1; i--)
{
for(j=i; j>=1; j--)
{
printf(“%c”,’A’+i);
}
printf(“\n”);
}
getch();
}
55. Program of using break statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
if(i==4)
{
break;
}
printf(“%d”,i);
}
getch();
}
56. Program of using continue statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1; i<=5; i++)
{
if(i==3)
{
continue;
}
printf(“%d”,i);
}
getch();
}
57. Program of using break and continue statement.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
if(i==3)
{
continue;
}
if(i==6)
{
break;
}
printf(“%d”,i);
}
getch();
}
58. Program to find the sum of two numbers by NON-
ANSI Style.

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a;
int b;
int sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=add_nums(a,b);
printf(“the sum is =%d”,sum);
getch();
}

int add_nums(x,y)
int x;
int y;
{
int result;
result=x+y;
return(result);
}
59. Program to find the product of two numbers by
NON-ANSI Style.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int multi;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
multi=multiplication(x,y);
printf(“the product is =%d”,multi);
getch();
}

int multiplication(x,y)
int x;
int y;
{
int result;
result=x*y;
return(result);
}
60. Program to find the sum of two numbers by ANSI
Style.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=add_nums(a,b);
printf(“the sum is=%d”,sum);
getch();
}

int add_nums(int x, int y)


{
int result;
result=x+y;
return(result);
}
61. Program of calling functions into called function.

#include<stdio.h>
#include<conio.h>
void add()
{
int a;
int b;
int sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=a+b;
printf(“the sum is =%d”,sum);
}

void sub()
{
int a;
int b;
int sub;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sub=a-b;
printf(“the subtraction is=%d”,sub);
}
void multi()
{
int a;
int b;
int mul;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
mul=a*b;
printf(“the product is =%d”,mul);
}

void main()
{
clrscr();
add();
add();
add();
sub();
sub();
sub();
multi();
multi();
multi();
getch();
}
62. Program of addition with parameter passing
method with ‘call by value’.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=add(a,b);
printf(“the sum is =%d”,sum);
getch();
}

int add(int x, int y)


{
int c;
c=x+y;
return(c);
}
63. Program of addition with parameter passing
method with ‘call by reference’.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a;
int b;
int sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=add(&a, &b);
printf(“the sum is =%d”,sum);
getch();
}

int add (int *x, int *y)


{
int *c;
*c=*x+*y;
return(*c);
}
64. Program of addition by automatic storage class.

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
auto a;
auto b;
auto sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=a+b;
printf(“the sum is =%d”,sum);
getch();
}
65. Program of addition by register storage class.

#include<stdio.h>
#include<conio.h>
viod main()
{
clrscr();
register a;
register b;
register sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=a+b;
printf(“the sum is =%d”,sum);
getch();
}
66. Program of addition by static storage class.

#include<stdio.h>
#include<conio.h>
viod main()
{
clrscr();
static a;
static b;
static sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=a+b;
printf(“the sum is =%d”,sum);
getch();
}
67. Program of addition by external storage class.

#include<stdio.h>
#include<conio.h>
viod main()
{
clrscr();
extern a;
extern b;
extern sum;
printf(“enter the value of a\n”);
scanf(“%d”,&a);
printf(“enter the value of b\n”);
scanf(“%d”,&b);
sum=a+b;
printf(“the sum is =%d”,sum);
getch();
}
68. Program to find the factorial by recursion function.

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
clrscr();
int n;
int ans;
printf(“enter the number\n”);
scanf(“%d”,&n);
ans=fact(n);
printf(“the factorial is =%d”,ans);
getch();
}

int fact(int x)
{
int f;
if(x==0)
{
return(1);
}
else
{
f=x*fact(x-1);
return(f);
}
}

You might also like