S.no |
TITLE |
1. |
Hello world |
2. |
Sum of two numbers |
3. |
Product of two numbers |
4. |
Perimeter of rectangle |
5. |
Greatest of three numbers(using operators) |
6. |
Nature of number |
7. |
To check whether the number is odd or even |
8. |
Fibonacci series |
9. |
Sum of natural numbers |
10. |
Interchange values |
11. |
Greatest of three numbers(nested if else) |
12. |
Program to check it’s a leap year or not |
13. |
Print day of a week(if else) |
14. |
Day of the week(switch) |
15. |
Factorial of a number |
16. |
Reverse |
17. |
Average of n numbers |
18 |
Factorial of a given positive integer |
19. |
Sum of first n numbers(using do-while loop) |
20. |
Program to calculate average for several different lists of number |
21. |
Print the figure |
22. |
Program to find hcf of two positive integers |
23. |
Find the biggest of n given numbers(using while loop) |
24. |
Average of n numbers(using do-while loop) |
25. |
Program to check the number is prime or not(using do-while loop) |
26. |
Function with no argument and no return |
27. |
Function with no argument with return |
28. |
Function with argument no return |
29. |
Function with argument with return |
30. |
Program to calculate factorial |
31. |
Exchange values of two variables(using call by value) |
32. |
Exchange values of two variables(using call by reference) |
33. |
Sum of series(using functions) |
34. |
Compute binomial coefficient(using function) |
35. |
Calculate smallest of the four numbers (using functions) |
36. |
Reverse of a number |
37. |
Find factorial of a number(using recursion) |
38. |
Program to compute a^b |
39. |
Program to calculate the marks obtained in 3 subjects |
40. |
Programs to check whether a student is passed in English |
41. |
Program to check if a number is divisible by 3 or 5 |
42. |
Program to display numbers lying between 1 to 100 which are divisible by number n |
43. |
To print the series |
44. |
To add, subtract and multiply two numbers (using switch) |
45. |
Program which reads of list of 10 numbers and print it in reverse order |
46. |
Calculate the average marks of 5 different students |
47. |
Array in one dimension |
48. |
Array in two dimension |
49. |
Multiplication of three numbers(using functions) |
50. |
Program to find diameter, circumference and area of a circle |
51. |
Swap two numbers |
52. |
Percentage of three numbers |
53. |
Program to find factorial of a number |
54. |
Square of a number |
55. |
Perimeter and area of a rectangle(using arguments without return) |
56. |
Perimeter and area of a rectangle(using without argument and with return) |
57. |
Maximum and minimum(using functions) |
58. |
Program to find the largest number(using array) |
59. |
Addition(using array) |
60. |
Addition of matrix |
61. |
Product of matrix |
62. |
Transpose of matrix |
63. |
Before and after calling from main |
64. |
Basic pointer program 1 |
65. |
Basic pointer program 2 |
66. |
Basic pointer program 3 |
67. |
Malloc |
68. |
Calloc |
69. |
Operations of pointers |
70. |
String |
71. |
Length of string |
1.HELLO WORLD
#include<stdio.h>
#include<conio.h>
void main()
{
printf("hello world");
getch();
}
OUTPUT
2.SUM OF TWO NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,sum;
printf("Enter the value of x");
scanf("%d",&x);
printf("Enter the value of y");
scanf("%d",&y);
sum=x+y;
printf("Sum=%d",sum);
getch();
}
OUTPUT
3.PRODUCT OF TWO NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,product;
printf("Enter the value of x:");
scanf("%d",&x);
printf("Enter the value of y:");
scanf("%d",&y);
product=x*y;
printf("product of two numbers= %d",product);
getch();
}
OUTPUT
4.PERIMETER OF RECTANGLE
#include<stdio.h>
#include<conio.h>
void main()
{
int length,breadth,perimeter;
printf("Enter length:");
scanf("%d",&length);
printf("Enter breadth:");
scanf("%d",&breadth);
perimeter=2*(length+breadth);
printf("%d",perimeter);
getch();
}
OUTPUT
5.GREATEST OF THREE NUMBERS
(using operators)
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
printf("Enter three numbers:");
scanf("%d%d%d",&x,&y,&z);
if(x>y && x>z)
printf("%d is greatest of the three numbers");
if (y>x && y>z)
printf("%d is greatest of the three numbers");
if (z>x && z>y)
printf("%d is greatest of the three numbers");
getch();
}
OUTPUT
6.NATURE OF NUMBER
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf("Enter a number");
scanf("%d",&x);
{
if (x>0)
printf("number is positive");
else
printf("number is negative");
}
getch();
}
OUTPUT
7.TO CHECK WHETHER THE NUMBER IS EVEN OR ODD
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
printf("Enter the number:");
scanf("%d",&x);
{
if (x%2==0)
printf("number is even");
else
printf("number is odd”);
}
getch();
}
OUTPUT
8.FIBONACC SERIES
#include <stdio.h>
#include<conio.h>
int main()
{
int a, b, c, i, n;
n = 4;
a = b = 1;
printf("%d %d ",a,b);
for(i = 1; i <= n-2; i++)
{
c = a + b;
printf("%d ", c);
a = b;
b = c;
}
getch();
}
OUTPUT
9.SUM OF NATURAL NUMBERS
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n,sum=0;
printf("Enter any number:");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
sum+i;
}
printf("sum of first %d natural numbers is %d",n,sum);
getch();
}
OUTPUT
10.INTERCHAGE VALUES
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,t;
printf("Enter two numbers to be exchanged");
scanf("%d%d",&a,&b);
t=a;
a=b;
b=t;
printf("Exchanged numbers are: a=%d \t b=%d",a,b);
getch();
}
OUTPUT
11.GREATEST OF THREE NUMBERS
(using nested if else)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("Biggest no= %d",a);
else
printf("Biggest no= %d",c);
}
else
{
if(b>c)
printf("Biggest no= %d",b);
else
printf("Biggest no= %d",c);
}
getch();
}
OUTPUT
12.PROGRAM TO CHECK IT’S A LEAP YEAR OR NOT
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf("Enter the year:");
scanf("%d",&year);
if (year%100==0)
{
if (year%400==0)
printf("year %d is a leap year",year);
else
printf("year %d is not a leap year",year);
}
else
{
if (year%4==0)
printf("year %d is a leap year”, year);
else
printf("year %d is not a leap year”, year);
}
getch();
}
OUTPUT
13.PRINT DAY OF A WEEK
(if else ladder)
#include<stdio.h>
#include<conio.h>
void main()
{
int day;
printf("Enter day of a week as number from 1-7:");
scanf("%d",&day);
if(day==1)
printf("day is Monday");
else if(day==2)
printf("day is Tuesday");
else if(day==3)
printf("day is Wednesday");
else if(day==4)
printf("day is Thursday");
else if(day==5)
printf("day is Friday");
else if(day==6)
printf("day is Saturday");
else if(day==7)
printf("day is Sunday");
else
printf("wrong input");
getch();
}
OUTPUT
14.DAY OF THE WEEK
(using switch)
#include<stdio.h>
#include<conio.h>
int main()
{
int day;
printf("Enter any number from 1-7:");
scanf("%d",&day);
switch(day)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday”)
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("Wrong input");
}
getch();
}
OUTPUT
15.FACTORIAL OF A NUMBER
( using while loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i= 1;
long fact= 1;
printf("Enter a number:");
scanf("%d",&n);
while(i<=n)
{
fact=fact *i;
i++;
}
printf("Factorial of %d= %ld",n,fact);
getch();
}
OUTPUT
16.REVERSE
#include<stdio.h>
#include<conio.h>
void main()
{
long rev = 0,num,rem, n;
printf("Enter the number:");
scanf("%d", &n);
num=n;
while(num !=0)
{
rem= num %10;
num= num /10;
rev= rev * 10 + rem;
}
printf("\n The actual number= %1d",n);
printf("\n The reverse number= %1d",rev);
getch();
}
OUTPUT
17.AVERAGE OF n NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float x,sum=0, avg;
printf("How many numbers:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter a number:");
scanf("%f",&x);
sum+=x;
}
avg=sum/n;
printf("The average=%f",avg);
getch();
}
OUTPUT
18.FACTORIAL OF A GIVEN POSITIVE INTEGER
(do-while loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1;
long fact=1;
printf("Enter a number:");
scanf("%d",&n);
do
{
fact *=i;
i++;
}
while(i<=n);
printf("Factorial of %d = %ld",n,fact);
getch();
}
OUTPUT
19.SUM OF FIRST n NUMBERS
(using do-while loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int sum, n, i= 0;
sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
do
{
sum+=i;
i++;
}
while(i<=n);
printf("Sum of first %d numbers= %d",n,sum);
getch();
}
OUTPUT
20.AVERAGE FOR SEVERAL DIFFERENT LISTS OF NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,lists;
float x,avg,sum;
printf("How many lists?:");
scanf("%d",lists);
for(i=1;i<=lists;i++)/*Outer loop for number of lists*/
{
sum=0;
printf("\n List number %d \n How many numbers?",i);
scanf("%d",&n);
printf("Enter the value of %d numbers",n);
for (j=1;j<=n;j++)/*Inner loop calculating sum of n numbers for all lists*/
{
scanf("%f",&x);
sum+=x;
}
avg=sum/n;
printf("\n The average is %f\n",avg);
}
getch();
}
OUTPUT
21.Print the figure:
*
**
***
****
.
.
.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
printf("\n How many rows?:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
getch();
}
OUTPUT
22.PROGRAM TO FIND HCF OF TWO POSTIVE INTEGERS
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,na,nb,r=1,hcf;
printf("Enter the two numbers:");
scanf("%d%d",&n1,&n2);
na=n1;
nb=n2;
if(n1>n2)
{
while(r!=0)
{
r=n1%n2;
n1=n2;
n2=r;
}
hcf=n1;
}
else
{
while(r!=0)
{
r=n2%n1;
n2=n1;
n1=r;
}
hcf=n2;
}
printf("\n HCF of %d and %d is %d",na , nb, hcf);
getch();
}
OUTPUT
23.FIND THE BIGGEST OF N GIVEN NUMBERS
(using While loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,big=0,num;
printf("How many numbers?:");
scanf("%d",&n);
printf("Enter %d numbers",n);
for(i=1;i<=n;i++)
{
scanf("%d",&num);
if (num>big)
big=num;
}
printf("Biggest number=%d",big);
getch();
}
OUTPUT
24.AVERAGE OF n NUMBERS
(using do-while loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1;
float x,avg,sum=0;
printf("How many numbers:");
scanf("%d",&n);
do
{
printf("\n x=");
scanf("%f",&x);
sum+=x;
i++;
}
while (i<=n);
avg=sum/n;
printf("The average of %d numbers=%f",n,avg);
getch();
}
OUTPUT
25.PROGRAM TO CHECK THE NUMBER IS PRIME OR NOT
(using do while loop)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("Enter a number:");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
printf("\n %d is not prime",n);
break;
}
}
if(i==n)
printf("\n %d is prime",n);
getch();
}
OUTPUT
26.FUNCTION WITH NO ARGUMENT AND NO RETURN VALUE
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{
sum();
getch();
}
void sum()
{
int a,b;
printf("Enter the two integers");
scanf("%d%d",&a,&b);
printf("The sum of number you Entered is %d",a+b);
}
OUTPUT
27.FUNCTION WITH NO ARGUMENT WITH RETURN
#include<stdio.h>
#include<conio.h>
int sum();
void main()
{
int x;
x=sum();
printf("Sum of the number you Entered is %d",x);
getch();
}
int sum()
{
int a,b;
printf("Enter the two integers");
scanf("%d%d",&a,&b);
return(a+b);
}
OUTPUT
28.FUNCTION WITH ARGUMENT NO RETURN
#include<stdio.h>
#include<conio.h>
void sum(int,int);// prototype
void main()
{
int a,b;
printf("Enter the two integers");
scanf("%d%d",&a,&b);
sum(a,b);//function call
getch();
}
void sum(int a,int b)// function defination
{
printf("The sum of the numbers you entered is %d",a+b);
}
OUTPUT
29.FUNCTION WITH ARGUMENT WITH RETURN
#include<stdio.h>
#include<conio.h>
int sum(int,int);
main()
{
int a,b,result;
printf("The sum of entered numbers is:");
scanf("%d%d",&a,&b);
result=sum(a,b);
printf("%d+%d=%d",a,b,result);
getch();
}
int sum(int x,int y)
{
int total;
total=x+y;
return(total);
}
OUTPUT
30.PROGRAM TO CALCULATE FACTORIAL
#include<stdio.h>
#include<conio.h>
void main()
{
long fact(int);
int num;
long f;
printf("Enter a number:");
scanf("%d",&num);
f=fact(num);
printf("Factorial of %d=%ld",num,f);
getch();
}
long fact(int n)
{
int i;
long f1=1;
for (i=1;i<=n;i++)
f1 = f1 *i;
return(f1);
}
OUTPUT
31.EXCHANGE VALUES OF TWO VARIABLES
(using call by value function)
/*Exchange of variables by call by value*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter two numbers");
scanf("%d%d",&a,&b);
exchange(a,b);
printf("\n The exchanged numbers are:%d%d",a,b);
getch();
}
exchange (int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
OUTPUT
32.EXCHANGE VALUES OF TWO VARIABLES
(using call by reference)
#include<stdio.h.>
#include<conio.h>
void main()
{
int a,b;
printf("\n Enter two numbers");
scanf("%d%d",&a,&b);
exchange(&a,&b);
printf("\n The exchanged contents are %d%d",a,b);
getch();
}
exchange(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
OUTPUT
33.SUM OF SERIES
(using function)
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum;
printf("Enter the last term of series:");
scanf("%d",&n);
sum=series(n);
printf("sum of series=%d",sum);
getch();
}
series(int last)
{
int i,s=0;
for(i=1;i<=last;i++)
s+=i;
return(s);
}
OUTPUT
34.COMPUTE BINOMIAL COEFFICIENT
(using function)
#include<stdio.h>
#include<conio.h>
void main()
{
int ncr;
long n,r;
printf("Enter the value of n and r:");
scanf("%1d%1d",&n,&r);
ncr=fact(n)/(fact(r)*fact(n-r));
printf("Value of ncr= %d",ncr);
getch();
}
fact(int num)
{
int i;
long f=1;
for(i=1;i<=num;i++)
f=f*i;
return(f);
}
OUTPUT
35.CALCULATE THE SMALLEST OF FOUR NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
int s1,s2,s3;
printf("Enter four numbers:");
scanf("%d%d%d%d",&a, &b, &c ,&d);
s1=small(a,b);
s2=small(c,d);
s3=small(s1,s2);
printf("The smallest of %d %d %d %d= %d",a,b,c,d,s3);
getch();
}
small(int x, int y)
{
if(x<y)
return(x);
else
return(y);
}
OUTPUT
36.REVERSE OF A NUMBER
REVERSE (int n)
{
int r, rev = 0;
while (n > 0)
{
r = n% 10 ;
n = n/10;
rev = rev* 10 + r;
}
return (rev);
}
OUTPUT
37.FIND FACTORIAL OF A NUMBER
(using recursion)
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
printf("The factorial of %d= %d",num,fact(num));
getch();
}
fact(int n)
{
if(n==0)
return(1);
else
return(n*fact(n-1));
}
OUTPUT
38.PROGRAM TO COMPUTE a^b
(using recursion)
#include<stdio.h>
#include<conio.h>
void main()
{
float power(float,int);
int b;
float a,p;
printf("Enter two numbers:");
scanf("%f%d",&a,&b);
p=power(a,b);
printf("%f raise to %d= %f",a,b,p);
getch();
}
float power(float x, int y)
{
if(y==0)
return(1);
else
return(x*power(x,y-1));
}
OUTPUT
39.PROGRAM TO CALCULATE THE MARKS OBTAINED IN 3 SUBJECTS
#include<stdio.h>
#include<conio.h>
main()
{
int mark_1,mark_2,mark_3;
float agg, per;
printf("Enter marks in English:");
scanf("%d",&mark_1);
printf("Enter marks in Hindi:");
scanf("%d",&mark_2);
printf("Enter marks in Maths:");
scanf("%d",&mark_3);
agg=mark_1+mark_2+mark_3;
per=agg/3;
printf("Percentage marks: %6.2f",per);
getch();
}
OUTPUT
40.PROGRAM TO CHECK WHETHER A STUDENT IS PASSED IN ENGLISH
#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
printf("Enter the marks of the student in English:");
scanf("%d",&marks);
if(marks>=50)
printf("Student has passed in English");
getch();
}
OUTPUT
41.PROGRAM TO CHECK IF A NUMBER IS DIVISIBLE BY BOTH 3 OR 5
#include<stdio.h>
int main()
{
int num;
printf("Enter a number");
scanf("%d",&num);
if ((num%3==0)&&(num%5==0))
{
printf("num is divisible by both");
}
else
{
printf("num is not divisible by 3 and 5");
}
return 0;
}
OUTPUT
42.PROGRAM TO DISPLAY NUMBERS LYING BETWEEN 1 TO 200 WHICH ARE DIVISIBLE BY NUMBER n
#include<stdio.h>
#include<conio.h>
main()
{
int i,c,n;
printf("Enter a number which you want to divide:");
scanf("%d",&n);
for(i=1;i<=200;i++)
{
c= i%n;
if(c==0)
{
printf("\n%d is divisible by %d",i,n);
}
}
getch();
}
OUTPUT
43.To print the series:
1
12
123
1234
.
.
.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
printf("\n How many rows?:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
getch();
}
OUTPUT
44.TO ADD,SUBTRACT AND MULTIPLY TWO NUMBERS
(using switch)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,choice,res;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
printf("\n1. addition");
printf("\n2. Subtraction");
printf("\n3. Multiplication");
printf("\nEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: res=a+b;
printf("%d +%d=%d",a,b,res);
break;
case 2: res=a-b;
printf("%d -%d=%d",a,b,res);
break;
case 3: res=a*b;
printf("%d *%d=%d",a,b,res);
break;
default: printf("Enter choice between 1 to 3 only");
}
getch();
}
OUTPUT
45.PROGRAM WHICH READS OF LIST OF 10 NUMBERS AND PRINT IT IN REVERSE ORDER
#include<stdio.h>
#include<conio.h>
void main()
{
int n[10],i;
printf("Enter the list of 10 numbers:");
for(i=0;i<=9;i++)
scanf("%d",&n[i]);
printf("\n The list in reverse order is:");
for (i=9; i>=0;i--)
printf("%d \t",n[i]);
getch();
}
OUTPUT
46.CALCULATE THE AVERAGE MARKS OF 5 DIFFERENT STUDENTS
#include<stdio.h>
#include<conio.h>
void main()
{
int m[5],i,s=0,avg;
for (i=0;i<5;i++)
{
printf("Enter the marks of %d student",i+1);
scanf("%d",&m[i]);
s=s+m[i];
}
avg=s/5;
printf("The average marks of a student=%d",avg);
getch();
}
OUTPUT
47.ARRAY IN ONE DIMENSION
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5];
for(int i=0;i<5;i++)
{
printf("Enter the array element");
scanf("%d",&a[i]);
}
for(int i=0;i<5;i++)
{
printf("the array is: %d",a[i]);
}
}
OUTPUT
48.ARRAY IN TWO DIMENSION
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j=0;
int a[3][3];
for(int i=0;i<3;j++)
{
for(int j=0;j<3;i++)
{
printf("Enter the array:");
scanf("%d",&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\n a[%d][%d]=%d \n",i,j,a[i][j]);
}
getch();
}
}
OUTPUT
49.MULTIPLICATION OF THREE NUMBERS
(using functions)
#include<stdio.h>
#include<conio.h>
void multiplication(int,int,int); //functional prototype
void main()
{
int a,b,c;
printf("Enter three numbers:");
scanf("%d%d%d",&a,&b,&c);
multiplication(a,b,c); //functional call
getch();
}
void multiplication(int a,int b, int c) //define
{
printf("multiplication of three numbers is %d",a*b*c);
}
OUTPUT
50.PROGRAM TO FIND DIAMETER, CIRCUMFERENCE AND AREA OF A CIRCLE
#include<stdio.h>
#include<conio.h>
int getdiameter(int);
int getcircumference(int);
int getarea(int);
int main()
{
float radius,diameter,circumference,area;
printf("Enter radius of a circle:");
scanf("%f",&radius);
diameter=getdiameter(radius);
circumference=getcircumference(radius);
area=getarea(radius);
printf("diameter of a circle is %.2f",diameter);
printf("\n circumference of a circle is %.2f",circumference);
printf("\n area of a circle is %.2f",area);
getch();
}
int getdiameter(int radius)
{
return(2*radius);
}
int getcircumference(int radius)
{
return(2*3.14*radius);
}
int getarea(int radius)
{
return(3.14*radius*radius);
}
OUTPUT
51.SWAP TWO NUMBERS
(using functions)
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
printf("Enter two integers:\n");
scanf("%d%d",&a,&b);
printf("a=%d and b=%d,before calling function\n",a,b);
swap(a,b);
printf("a=%d and b=%d,after calling function\n",a,b);
getch();
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("a=%d and b=%d,in function",a,b);
}
OUTPUT
52.PERCENTAGE OF THREE NUMBERS
(using functions)
#include<stdio.h>
#include<conio.h>
int si(int,int,int);
void main()
{
float p,r,t;
printf("Enter three numbers:");
scanf("%f%f%f",&p,&r,&t);
si(p,r,t);
printf("si is %f",p*r*t/100);
getch();
}
int si(int p,int r, int t)
{
return(p*r*t/100);
}
OUTPUT
53.PROGRAM TO FIND FACTORIAL OF A NUMBER
(using functions)
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,factorial;
printf("Enter a number:");
scanf("%d",&n);
factorial=fact(n);
printf("factorial of %d number is %d",n,factorial);
}
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}
OUTPUT
54.SQUARE OF A NUMBER
#include<stdio.h>
#include<conio.h>
int square (int);
void main()
{
int n,answer;
printf("Enter a number:");
scanf("%d",&n);
answer=square(n);
printf("Square of a number is %d",answer,n);
}
int square(int n)
{
return(n*n);
getch();
}
OUTPUT
55.PERIMETER AND AREA OF A RECTANGLE
(using with arguments without return)
#include<stdio.h>
#include<conio.h>
void rec_area(int,int);
void rec_perimeter(int,int);
void main()
{
int l,b;
printf("Enter two numbers:");
scanf("%d%d",&l,&b);
rec_area(l,b);
rec_perimeter(l,b);
}
void rec_area(int l,int b)
{
printf("area of rectangle is %d", l*b);
}
void rec_perimeter(int l,int b)
{
printf("\n perimeter of rectangle is %d",2*(l+b));
}
OUTPUT
56.PERIMETER AND AREA OF A RECTANGLE
(using without argument and with return)
#include<stdio.h>
#include<stdio.h>
int area();
int perimeter();
void main()
{
int x,y;
x=area();
y=perimeter();
printf("Area of rectangle is %d",x);
printf("\n perimeter of rectangle is %d",y);
}
int area()
{
int l,b;
printf("Enter two numbers:");
scanf("%d%d",&l,&b);
return(l*b);
}
int perimeter()
{
int l,b;
printf("Enter values of l and b:");
scanf("%d%d",&l,&b);
return(2*(l+b));
}
OUTPUT
57.MAXIMUM AND MINIMUM
(using functions)
#include<stdio.h>
#include<conio.h>
int max(int,int);
int min(int,int);
void main()
{
int n1,n2,maximum,minimum;
printf("Enter two numbers:");
scanf("%d%d",&n1,&n2);
maximum=max(n1,n2);
minimum=min(n1,n2);
printf("maximum=%d",maximum);
printf("\n minimum=%d",minimum);
}
int max(int n1,int n2)
{
return(n1>n2)?n1:n2;
}
int min(int n1,int n2)
{
return(n1>n2)?n2:n1;
}
OUTPUT
58.PROGRAM TO FIND THE LARGEST NUMBER
(using arrays)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float a[100];
printf("Enter number of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter number %d:",i+1);
scanf("%f",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[0]<a[i])
a[0]=a[i];
}
printf("largest number is %f",a[0]);
getch();
}
OUTPUT
59.ADDITITION
(using arrays)
#include<stdio.h>
int main()
{
int n,sum=0,c,array[100];
printf("Enter how many numbers:");
scanf("%d",&n);
for (c=0;c<n;c++)
{
printf("Enter the number:");
scanf("%d",&array[c]);
sum=sum+array[c];
}
printf("Sum=%d\n",sum);
return 0;
}
OUTPUT
60.ADDITION OF MATRIX
#include<stdio.h>
#include<conio.h>
void main()
{
int a [10][10],b[10][10],s[10][10],r,c,i,j;
printf("\n Enter rows and columns of 2 matrices:");
scanf("%d%d",&r,&c);
printf("Enter elements of first matrix:");
for(i=0; i<r; i++)
for(j=0;j<c;j++)
scanf("%d",&a[i] [j]);
printf("\n Enter elements of second matrix:");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&b[i][j]);
/*Sum of the two matrices is*/
for(i=0;i<r;i++)
for(j=0;j<c;j++)
s[i][j]=a[i][j]+b[i][j];
printf("Sum of two matrices is:\n");
for (i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d \t",s[i][j]);
printf("\n");
}
getch();
}
OUTPUT
61.PRODUCT OF MATRIX
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
system("cls");
printf("enter the number of row=");
scanf("%d",&r);
printf("enter the number of column=");
scanf("%d",&c);
printf("enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("multiply of the matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
OUTPUT
62.TRANSPOSE OF MATRIX
#include<stdio.h>
#include<conio.h>
void transpose(int [][10],int,int);
void diplay(int [][10],int,int);
main()
{
int a[10][10];
int i,j,rows,cols;
printf("Enter number of rows:");
scanf("%d",&rows);
printf("Enter number of columns:");
scanf("%d",&cols);
printf("Enter row wise %d integers\n",rows*cols);
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
{
scanf("%d",&a[i][j]);
}
display(a,rows,cols);
transpose(a,rows,cols);
getch();
}
void transpose(int x[][10],int p, int q)
{
int i,j,k;
int y[10][10];
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
y[j][i]=x[i][j];
}
printf("transpose is:");
display(y,q,p);
}
void display(int c[][10],int m,int n)
{
int i,j;
printf("Displaying %d by %d data\n",m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
OUTPUT
63.BEFORE AND AFTER CALLING FROM MAIN #include<stdio.h>
#include<conio.h>
void modify (int[],int);
main()
{
int x[]={10,20,30,40,50};
int i,count;
count=sizeof(x)/sizeof(x[0]);
printf("----From main,before calling---\n");
for(i=0;i<count;i++)
{
printf("%d\t",x[i]);
}
modify(x,count);
printf("\n---From main after calling---\n");
for(i=0;i<count;i++)
{
printf("%d\t",x[i]);
}
getch();
}
void modify(int a[],int m)
{
int i;
printf("\n---From within function---\n");
for(i=0;i<m;i++)
{
a[i]=-1;
printf("%d\t",a[i]);
}
return;
}
OUTPUT
64.BASIC POINTER PROGRAM 1
#include<stdio.h>
int main()
{
int num=50;
int p;
p=#
printf("Address of p variable is %x \n",p);
printf("Value of p variable is %d,p");
return 0;
}
OUTPUT
65.BASIC POINTER PROGRAM 2
#include<stdio.h>
int main()
{
int i=5;
int ptr;
ptr=NULL;
printf("Value of i=%d",i);
printf("\n address of i=%u",&i);
printf("\n Value of ptr= %u",ptr);
getch();
}
OUTPUT
66.BASIC POINTER PROGRAM 3
#include<stdio.h>
#include<conio.h>
int main()
{
int i=3,*ptr1,**ptr2;
ptr1= &i;
ptr2= &ptr1;
printf("value of i=%d",i);
printf("\n value of *ptr1=%d",ptr1);
printf("\n value of **ptr2=%d",**ptr2);
getch();
}
OUTPUT
67.CALLOC
#include<stdio.h>
#include<conio.h>
main()
{
int *i,*j;
int *ptr;
ptr= calloc(5,sizeof(int));
if(ptr!=NULL)
{
printf("Default values are---\n");
for(j=0,i=ptr;j<5;i++,j++)
printf("i=%u and *i=%d\n",i,*i);
for(i=ptr,j=0;j<5;i++,j++)
*i=j+1;
printf("New values are---\n");
for(j=0,i=ptr; j<5;i++,j++)
printf("i=%u and *i=%d\n",i,*i);
}
else
{
printf("\ncalloc() failed-out of memory");
return(1);
}
getch();
}
OUTPUT
68.MALLOC
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr,*ptrl;
int n,i;
n=5;
printf("Enter number of elements: %d\n",n);
ptr= (int*)malloc(n*sizeof(int));
if(ptr== NULL)
{
printf("Memory not allocated.\n");
}
else
{
printf("Memory successfully allocated using malloc.\n");
for(i=0;i<n;i++)
{
ptr[i]=i+1;
}
printf("the elements of array are:");
for(i=0;i<n;i++)
{
printf("%d",ptr[i]);
}
}
return 0;
}
OUTPUT
69.OPERATIONS OF POINTERS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr;
int n,i;
n=5;
printf("Enter number of elements: %d\n",n);
ptr= (int*)calloc(n,sizeof(int));
if(ptr== NULL)
{
printf("Memory not allocated.\n");
}
else
{
printf("Memory successfully allocated using calloc.\n");
for(i=0;i<n;i++)
{
ptr[i]=i+1;
}
printf("the elements of array are:");
for(i=0;i<n;i++)
{
printf("%d",ptr[i]);
}
n=10;
printf("\n Enter the new size of the array:%d\n",n);
ptr=realloc(ptr,n*sizeof(int));
printf("memory successfully reallocated using re-alloc.\n");
for(i=5;i<n;i++);
}
return 0;
}
OUTPUT
70.STRING
#include<stdio.h>
#include<conio.h>
struct date
{
int dd;
int mm;
int yy;
};
void main()
{
struct date d[10];
struct date *ptr;
int i;
printf("Input a date (dd/mm/yyyy) :\n");
for(i=1,ptr=d;ptr<=(d+2);ptr++,i++)
{
printf("Date %d :",i);
scanf("%d%d%d",&ptr->dd,&ptr->mm,&ptr->yy);
}
printf("----OUTPUT-----");
for(i=1,ptr=d;ptr<=(d+2);ptr++,i++)
{
printf("\nDate %d :",i);
printf("%d/%d/%d",ptr->dd,ptr->mm,ptr->yy);
}
getch();
}
OUTPUT
71.LENGTH OF STRING
#include<stdio.h>
#include<conio.h>
struct date
{
int dd;
int mm;
int yy;
};
void main()
{
struct date d[10];
struct date *ptr;
int i;
printf("Input a date (dd/mm/yyyy) :\n");
for(i=1,ptr=d;ptr<=(d+2);ptr++,i++)
{
printf("Date %d :",i);
scanf("%d%d%d",&ptr->dd,&ptr->mm,&ptr->yy);
}
printf("----OUTPUT-----");
for(i=1,ptr=d;ptr<=(d+2);ptr++,i++)
{
printf("\nDate %d :",i);
printf("%d/%d/%d",ptr->dd,ptr->mm,ptr->yy);
}
getch();
}
OUTPUT
THANK
YOU