You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<stdio.h>voidmain()
{
intx,y,sum;
printf("Enter the two number to be added\n");
scanf("%d%d",&x,&y);
sum=x+y;
printf("Sum : %d + %d = %d \n",x,y,sum);
}
2. AVG.OF N NUMBER
#include<stdio.h>voidmain()
{
intn;
floatsum=0;
printf("Enter number of elements \n");
scanf("%d",&n);
inta[n];
printf(" now enter %d elements\n",n);
for(intj=1;j<=n;j++)
{
scanf("%d",&a[j]);
sum+=a[j];
}
floatavg;
avg=sum/n;
printf("Average of %d elements is %0.2f \n",n,avg);
}
3. WEEKDAYS BY USING SWITCH STATEMENT
#include<stdio.h>voidmain()
{
intx;
printf("Enter any integer between 1 to 7\n");
scanf("%d",&x);
switch(x)
{
case1:
printf("MONDAY\n");
break;
case2:
printf("TUESDAY\n");
break;
case3:
printf("WEDNESDAY\n");
break;
case4:
printf("THRUSDAY\n");
break;
case5:
printf("FRIDAY\n");
break;
case6:
printf("SATURDAY\n");
break;
case7:
printf("SUNDAY\n");
break;
default :
printf("Enter number between 1 to 7\n");
break;
}
}
4. NUMBER IS EVEN OR ODD
#include<stdio.h>voidmain()
{
inta;
printf("enter the number\n");
scanf("%d",&a);
if(a%2==0)
{
printf("EVEN\n");
}
else
{
printf("ODD\n");
}
}
'''
----
## 5. TABLE OF ANY NUMBER
```C#include<stdio.h>intmain()
{
intn,i;
printf("enter the number \n");
scanf("%d",&n);
printf("\t\t\tTABLE OF %d\n",n);
printf("\t\t\t==========\n");
for(i=1;i<11;i++)
{
printf("%d * %d = %d\n",n,i,n*i);
}
return0;
}
6. ARMSTRONG NUMBER
#include<stdio.h>intmain()
{
intsum=0,digit;
intn, temp;
printf("enter any positive integer number");
scanf("%d",&n);
temp=n;
while(temp>0)
{
digit=temp%10;
temp/=10;
sum=sum+digit*digit*digit;
}
if(n==sum)
printf("\n %d is a armstrong number\n",n);
elseprintf("\n %d is not a armstrong number\n",n);
}
#include<stdio.h>intmain()
{
inti,n,k,temp;
printf("\n enter the array size\n");
scanf("%d",&n);
inta[n];
printf("enter %d elements of array\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(k=0;k<n-1;k++)
{
for(i=0;i<n-k-1;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf("\n array elements after shorting\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
}
9. BINARY SEARCH
#include<stdio.h>intmain()
{
intm,n,a[100],search,first,last,middle;
printf("Enter the size of array");
scanf("%d",&m);
printf("Enter %d numbar\n",m);
for(n=0;n<m;n++)
scanf("%d",&a[n]);
printf("Enter the the number u want to search\n");
scanf("%d",&search);
first=0;
last=m-1;
middle=(first+last)/2;
while(first<=last)
{
if(a[middle]<search)
first=middle+1;
elseif(a[middle]==search)
{
printf("%d found at location %d\n",search,middle+1);
break;
}
elselast=middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("Not found! %d is not present in the list \n",search);
return0;
}
#include<stdio.h>intmain()
{
intsum=0,i=1;
while(i<101)
{
sum=sum+i;
i++;
}
printf("sum of numbers from 0 to 100 is %d\n",sum);
return0;
}
13. FIND GREATER BETWEEN TWO GIVEN NUMBERS
#include<stdio.h>voidmain()
{
floata,b;
printf("enter first number\n");
scanf("%f",&a);
printf("enter the second nummber\n");
scanf("%f",&b);
if(a>b)
printf("%f is greater\n",a);
elseif(b>a)
printf("%f is greater\n",b);
elseprintf("both numbers are equal\n");
}
14. GREATER AMONG THREE NUMBERS
#include<stdio.h>voidmain()
{
inta,b,c;
printf("enter the three numbers which you want to compare \n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("\n%d is the greatest number\n",a);
elseif(b>a&&b>c)
printf("\n%d is the greatest number\n",b);
elseprintf("\n%d is the greatest number\n",c);
}
#include<stdio.h>intmain()
{
inta;
printf("enter the year\n");
scanf("%d",&a);
if(a%4==0)
printf("it is a leap year\n");
elseprintf("it is not a leap year\n");
}
17. LINEAR SEARCH
#include<stdio.h>intcheck(intb[],intm,into)
{intp=-1;
for(inti=1;i<=m;i++)
{
if(b[i]==o)
p=i;
}
returnp;
}
voidmain()
{
intn,num,index;
printf("enter the array size\n");
scanf("%d",&n);
inta[n];
printf("enter the array elements\n");
for(inti=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("now enter the number which you want to check\n whether it is present or not in entered array\n");
scanf("%d",&num);
index=check(a,n,num);
if(index==-1)
printf("element is not found\n");
elseprintf("element is found at the position %d \n",index);
}
18. SUM OF TWO MATRIX
include<stdio.h>voidmain()
{
inta[10][10],b[10][10],c[10][10];
intm,n,i,j;
printf("Enter size of matrix A as m,n:");
scanf("%d%d",&m,&n);
printf("\nEnter elements of matrix A rowwise m*n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the elements of second matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=b[i][j]+a[i][j];
}
}
printf("\nSUM OF MATRIX A&B \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
}
19. TRANSPOSE MATRIX
#include<stdio.h>intmain()
{
intm,n,i,j;
printf("enter the number of rows and columns of matrix\n");
scanf("%d%d",&m,&n);
inta[m][n],b[m][n] ;
printf("enter the elements of matrix row wise\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[j][i]=a[i][j];
}
}
printf("transpose of matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
}
20. SUM OF DIGITS OF A NUMBER
#include<stdio.h>intmain()
{
inta,sum=0,c;
printf("enter the number\n");
scanf("%d",&a);
while(a!=0)
{
c=a%10;
sum+=c;
a=a/10;
}
printf("sum of digits is %d\n",sum);
}
21. CHECK PALINDROME NUMBER
#include<stdio.h>intmain()
{
intsum=0,digit;
intn, temp;
printf("enter any positive integer number\n");
scanf("%d",&n);
temp=n;
while(temp>0)
{
digit=temp%10;
temp/=10;
sum=sum*10+digit;
}
if(n==sum)
printf("\n %d is a palidrome number\n",n);
elseprintf("\n %d is not a palidrome number\n",n);
}
22. CALL BY VALUE
#include<stdio.h>voidswap(inta,intb);
voidmain()
{
intx,y;
printf("\n Enter value for x:");
scanf("%d",&x);
printf("\n Enter value for y:");
scanf("%d",&y);
printf("\n Before calling swap functin\n");
printf("\n Value of x=%d,Value of y=%d\n",x,y);
swap(x,y);
printf("\n After returning from swap function");
printf("\n Value of x=%d,value of y=%d\n",x,y);
}
voidswap(inta,intb)
{
inttemp;
printf("\n Inside the function \n");
printf("\n Value of a=%d,Value of b=%d before swaping\n",a,b);
temp=a;
a=b;
b=temp;
printf("\n Value of a=%d,Value of b=%d after swaping\n",a,b);
}
23. CALL BY REFERENCE
#include<stdio.h>voidswap(int*,int*);
voidmain()
{
intx,y;
printf("\n Enter value for x:");
scanf("%d",&x);
printf("\n Enter value for y:");
scanf("%d",&y);
printf("\n Before calling swap functin\n");
printf("\n Value of x=%d,Value of y=%d\n",x,y);
swap(&x,&y);
printf("\n After returning from swap function");
printf("\n Value of x=%d,value of y=%d\n",x,y);
}
voidswap(int*a,int*b)
{
inttemp;
printf("\n Inside the function \n");
printf("\n Value of a=%d,Value of b=%d before swaping\n",*a,*b);
temp=*a;
*a=*b;
*b=temp;
printf("\n Value of a=%d,Value of b=%d after swaping\n",*a,*b);
}
#include<stdio.h>structfraction
{
intnum;
intden;
};
voidmain()
{
intrnum,rden;
structfractionf1,f2;
printf("enter numerator and denominator of first fraction\n");
scanf("%d%d",&f1.num,&f1.den);
printf("enter numerator and denominator of second fraction\n");
scanf("%d%d",&f2.num,&f2.den);
rnum=f1.num*f2.num;
rden=f1.den*f2.den;
printf("\nproduct is : %d/%d\n",rnum,rden);
}