Sei sulla pagina 1di 12

1.

Program for input any positive integer and check it is Perfect number or not

/*given no. is perfect no. is not*/


#include<stdio.h>
void main()
{
int n,i=1,sum=0;
printf("enter a number:");
scanf("%d",&n);
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);
getch();
}
2. Program for input any positive integer and check it is Armstrong number or not

/*armstrong number or not*/


#include<stdio.h>
void main()
{
int n,k,r,s=0;
clrscr();
printf("enter a positive integer:"),
scanf("%d",&n);
k=n;
while(n!=0)
{
r=n%10;
s+=r*r*r;
n=n/10;
}
if(s==k)
printf("%d is an armstrong no.",k);
else
printf("%d is not an armstrong no.",k);
getch();
}
3. Program for input any positive integer and find sum of individual digits in given integer

/*sum of individual digits of given positive integer*/


#include<stdio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("enter a positive integer\n");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("the sum of individual digits of a positive integer is
%d",s);
getch();
}
4. Program for print Fibonacci number series from 0 to n

/*fibonacci series for 0 to n*/


#include<stdio.h>
#include<conio.h>
void main()
{
int f0,f1,f,n,i;
clrscr();
printf("enter the value for n\n");
scanf("%d",&n);
f0=0;
f1=1;
printf("fibonacci sequence for the first %d terms:\n",n);i=0;
while(i<n)
{
printf("%d\t",f0);
f=f0+f1;
f0=f1;
f1=f;
i=i+1;
}
getch();
}
5. Program for input any integer and check it is Prime number or not

/*given no. is prime or not*/


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,c=0;
clrscr();
printf("enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
if(n%i==0)
c++;
if(c==2)
printf("\n%d is an prime no.",n);
else
printf("%d is not an prime no.",n);
getch();
}
6. Program for input any array and find minimum and maximum element in that array.

/*finding big and small no. in an array*/


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,small,large;
clrscr();
printf("enter the array size:");
scanf("%d",&n);
printf("enter elements of array");
for(i=0;i<n;i++)//read the elements of an array
scanf("%d",&a[i]);
small=a[0];
large=a[0];
for(i=0;i<n;i++)//read the elements of an array
{
if(a[i]<small)//check the condition for min. value small=a[i];
small=a[i];
if(a[i]>large)//check the condition for max. value large=a[i];
large=a[i];
}
printf("largest value is %d\n",large);
printf("smallest value is %d\n",small);
getch();
}
7. Program for input any two matrices using two dimensional array and perform Matrix
multiplication

/*matrix multiplication*/

#include<stdio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j,k;
clrscr();

//1st matrix elements reading


printf("enter a matrix elements");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}

//second matrix reading


printf("enter b matrix elements");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}

//c[i][j]=0
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
}
}
//printing matrix multiplication process
printf("multiplication of matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
c[i][j]+=a[i][k]+b[k][j];
}
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("c[%d][%d]=%d\n",i,j,c[i][j]);
}
}
getch();
}
8. Program for input any two matrices using two dimensional array and perform Matrix
addition

/*matrix addition*/

#include<stdio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();

//1st matrix elements reading


printf("enter a matrix elements");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}

//second matrix reading


printf("enter b matrix elements");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}

//printing matrix addition process


printf("multiplication of matrix is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf(“after adding c matrix is\n”);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("c[%d][%d]=%d\n",i,j,c[i][j]);
}
}
getch();
}
9. Program for input any array and sort it in ascending order using Bubble sort method

/*sorting elements in an array using bubble sort*/


#include<stdio.h>
void main()
{
int i,j,a,n,number[30];
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
printf("enter the numbers\n");
for(i=0;i<n;i++)
scanf("%d",&number[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(number[j]>number[j+1])
{
a=number[j];
number[j]=number[j+1];
number[j+1]=a;
}
}
}
printf("the numbers arranged in ascending order are given
below\n");
for(i=0;i<n;++i)
printf("%d\n",number[i]);
getch();
}
10. Program for declare a structure with student marks details and calculate and print sum
and average

/*calculating total and average students marks using structure*/


#include<stdio.h>
#include<conio.h>
struct student
{
int rl;
char nm[20];
int m1;
int m2;
int m3;
int t;
int maxmarks;
float per;
};
void main()
{
struct student a;
clrscr();
printf("enter rollno., name, 3 sub marks and max marks in
order\n");
scanf("%d%s%d%d%d%d",&a.rl,&a.nm,&a.m1,&a.m2,&a.m3,&a.maxmarks);
a.t=a.m1+a.m2+a.m3
a.per=a.t/a.maxmarks*100
printf("rollno.=%d\n",a.rollno.);
printf("name:%sk\n",a.nm);
printf("m1:%d\n",a.m1);
printf("m2:%d\n",a.m2);
printf("m3:%d\n",a.m3);
printf("total:%d\n",a.t);
printf("per:%f\n",a.per);
getch();
}

Potrebbero piacerti anche