Anda di halaman 1dari 43

1.

#include<stdio.h>

#include<conio.h>

void main()

int j;

char c;

a:

clrscr();

printf("enter the ACII code (0 to 127) : ");

scanf("%d",&j);

if(j>127)

printf("u hav entered wrong code");

goto a;

else

c = j;

printf("character corresponding to %d is %c",j,c);

}
#include<stdio.h>

void main()

int a,b,c,d,i;

printf("The armstrong number between 1 to 500 are : ");

i = 1;

while(i<=500)

c=i;

d =i;

b = 0;

a = 0;

while(c>0)

a = c%10;

b +=a*a*a;

c = c/10;

if(b==d)

printf("\n%d",i);

i++;

}
#include<stdio.h>

#include<conio.h>

void main()

int a,b,j;

int d;

for(; d!=0;)

printf("enter the operator \n 1 for + \n 2 for - \n 3 for * \n 4 for / \n 5 for % \n");

scanf("%d",&j);

printf("\nenter the two numbers:");

scanf("%d%d",&a,&b);

switch(j)

case 5:

printf("u have entered % sign so the result is: %d" , a%b);

break;

case 1:

printf("u have entered + sign so the result is: %d" , a+b);

break;
case 2:

printf("u have entered - sign so the result is: %d" , a-b);

break;

case 3:

printf("u have entered * sign so the result is: %d" , a*b);

break;

case 4:

printf("u have entered /sign so the result is: %d" , a/b);

break;

default :

printf("u have entered invalid operator") ;

printf("\ndo u wish to continue press 0/1 :");

scanf("%d",&d);

}
#include<stdio.h>

#include<conio.h>

void main()

int a,b,d,c;

char x;

clrscr();

printf("enter the real part of 1st complex number: ");

scanf("%d",&a);

printf("enter the complex part of the 1st complex number: ");

scanf("%d",&b);

printf("enter the real part of 2nd complex number: ");

scanf("%d",&c);

printf("enter the complex part of the 2nd complex number: ");

scanf("%d",&d);

printf("the two complex number entered are %d + j%d and %d + j%d" ,a,b,c,d);

printf("\nenter + or - :");

scanf("%c",&x);

if(x=='+')

printf("complex number after adding is %d + j%d " , (a+c),(b+d));

else if(x=='-')

printf("complex number after subtraction is %d + j%d " , (a-c),(b-d));

else

printf("u hav entered wrong operator");


}
#include<stdio.h>

void main()

int n,num,x,sum=0,count=0,a,last,first,multiple=1;

printf("Enter a number: ");

scanf("%d",&n);

a=n;

while(n>0)

x=n%10;

sum=sum+x;

n=n/10;

count++;

printf("Sum of digits of a number=%d \n the number of digits is %d",sum,count);

last = a%10;

printf("\nthe last digit is %d ",last );

for(;count-1;)

multiple *=10;

count--;

printf("\nthe first digit is %d ",first=a/multiple);


printf("\nthe sum of digits excluding first and last digit is %d " ,sum-first-last);

}
#include<stdio.h>

int arm(int);

void main()

int a,b;

printf("enter the number: ");

scanf("%d",&a);

b = arm(a);

if(b==a)

printf("the entered number is armstrong");

else

printf("the given number is not armstrong");

int arm(int x)

int b = 0,a = 0;

while(x>0)

a = x%10;

b +=a*a*a;

x = x/10;

return b;

}
#include<stdio.h>

int fact(int);

void main()

int a,d;

printf("enter the number: ");

scanf("%d",&a);

d = fact(a);

printf("\nthe factorial of entered number is %d",d);

int fact(int x)

int i=1,b=1 ;

while(i<=x)

b = b*i;

i++;

return b;

}
#include<stdio.h>

int lcm(int,int);

int hcf(int,int);

void main()

int d,a,b;

printf("enter the two number whose lcm or hcf should be find :" );

scanf("%d%d",&a,&b);

printf( "the hcf of the numbers is:");

d = hcf(a,b);

printf("%d",d);

printf( "\nthe lcm of the numbers is:");

d = lcm(a,b);

printf("%d",d);

int lcm(int x, int y)

int b;

b = x*y/hcf(x,y);

return b;

int hcf(int x,int y)

{
int temp, d;

if(y>x)

temp = x;

x=y;

y = temp;

d = y;

while(1)

if(x%d==0&&y%d==0)

return d;

else

d --;

}
#include<stdio.h>

void main()

int a;

b:

printf("enter the year :");

scanf("%d",&a);

if(a<0)

{printf("you hav entered invalid year") ;

goto b;}

else

if(a%4==0)

printf("the entered year is leap year");

else

printf("the entered year is not a leap year");

}
#include<stdio.h>

#include<string.h>

void main()

char str[20] , pat[20] ;

int i=0,j,k=0 ;

printf("enter the first string :");

gets(str);

printf("\nenter the 2nd string : ");

gets(pat);

while(str[i]!='\0')

if(str[i]==pat[0])

j=1;

while(pat[j]!='\0'&&str[j+i]!='\0'&&pat[j]== str[j+i])

j++;

k = 1;

if(pat[j]=='\0')

printf("pattern string found at %d position " , i+1);


}

i++;

if(k==0)

{if(str[j+i]=='\0')

printf("pattern not found ") ;

}
#include<stdio.h>

void main()

int i,*p,a[10];

p = a;

printf("enter number in an array:\n ");

for(i=0;i<10;i++)

scanf("%d",(p+i));

printf("the number u hav entered are: ");

for(i=0;i<10;i++)

printf("%d ",*(p+i));

}
#include<stdio.h>

void main()

int i,*p,a[10],c,flag =0;

p = a;

printf("enter number in an array:\n ");

for(i=0;i<10;i++)

scanf("%d",(p+i));

printf("the number u hav entered are: ");

for(i=0;i<10;i++)

printf("%d ",*(p+i));

printf("\n enter the number u want to find: ");

scanf("%d",&c);

i=0;

for(p=a ;p+i<(p+10);i++)

if(*(p+i)==c)

printf("\n number found at %d position ",i+1 );

flag = 1;

break;
}

else

continue;

if(flag==0)

printf("\nnumber not found " );

}
#include<stdio.h>

void main()

int c,d, i = 3;

printf("prime number between 2 to 300 are :");

printf("\n 2");

while(i<=300)

for(d = 2;d<(i-1);d++)

c = i%d;

if (c==0)

break;

if(c!=0)

printf("\n%d",i);

i++;

}
#include <stdio.h>

void main()

int i,j;

for(i=1;i<=5;i++)

for(j=1;j<=i;j++)

if(i%2==0)

if(j%2==0)

printf("# ");

else

printf("* ");

else

if(j%2==0)

printf("# ");

else

printf("* ");

printf("\n");

}
}
#include<stdio.h>

void main()

int i,j,c;

for(i=1;i<=5;i++)

for(j=1;j<=i;j++)

printf("%6d",i);

printf("\n");

}
#include<stdio.h>

void main()

char a[20];

int i,j,b;

printf("enter the string: ");

gets(a);

for(i=0;a[i]!='\0';i++)

if(a[i]==' ')

printf("do you want to remove %d blank 1/0:" ,i+1);

scanf("%d",&b);

if(b==1)

j=i;

for(; a[j]!='\0';j++)

a[j]=a[j+1];

else

continue;

for(j =0 ; a[j]!='\0';j++)

printf("%c",a[j]);
}
#include<stdio.h>

void main()

char a[10],b[10],c[20],d;

int i=0,j,k;

printf("enter the 1st string :");

gets(a);

printf("enter the 2nd string :" );

gets(b);

for(k=0;a[k]!='\0';k++)

c[i++]=a[k];

printf("do you want to enter space between words y/n :");

scanf("%c",&d);

if(d=='y')

c[i++] = ' ';

for(j=0;b[j]!='\0';j++)

c[i++] = b[j];

else

for(j=0;b[j]!='\0';j++)

c[i++] = b[j];

c[i++] = '\0';
for(i = 0;c[i]!='\0';i++)

printf("%c",c[i]);

}
#include<stdio.h>

void main()

char a[20];

int i,j=0;

printf("enter the string : ");

gets(a);

for(i=0;a[i]!='\0';i++)

j++;

printf("the length of the string is %d ", j);

}
#include<stdio.h>

void main()

int a,b;

printf("enter two numbers : ");

scanf("%d%d",&a,&b);

printf("number before swapping %d %d",a,b);

a = a+b;

b = a -b;

a = a - b;

printf("\nnumber after swapping %d %d ",a,b);

}
#include<stdio.h>

void main()

int a,b,c,d;

printf("enter the four numbers : ");

scanf("%d%d%d%d",&a,&b,&c,&d);

if(a>b)

if(a>c)

if(a>d)

printf("%d is greatest",a);

else

printf("%d is greatest",d);

else

if(c>d)

printf("%d is greatest",c);

else

printf("%d is greatest",d);

else
{

if(b>c)

if(b>d)

printf("%d is greatest",b);

else

printf("%d is greatest",d);

else

if(c>d)

printf("%d is greatest",c);

else

printf("%d is greatest",d);

}
#include<stdio.h>

#include<string.h>

void main()

char str[20] , pat[20] ;

int i=0,j,k=0 ;

printf("enter the first string :");

gets(str);

printf("\nenter the 2nd string : ");

gets(pat);

while(str[i]!='\0')

if(str[i]==pat[0])

j=1;

while(pat[j]!='\0'&&str[j+i]!='\0'&&pat[j]== str[j+i])

j++;

k = 1;

if(pat[j]=='\0')

printf("pattern string found at %d position " , i+1);


}

i++;

if(k==0)

{if(str[j+i]=='\0')

printf("pattern not found ") ;

}
#include<stdio.h>

int pro(int , int);

void main()

int a ,b,c ;

printf("enter the numbers :");

scanf("%d%d" , &a , &b);

c = pro(a,b);

printf("%d to the power %d is %d",a,b,c);

int pro(int x,int y)

int c=1,d=1;

if(y==0)

printf("%d" ,1);

if(x==0)

printf("%d", 0);

if((x!=0&&y!=0))

while(c<=y)
{

d*=x;

++c;

return d;

Anda mungkin juga menyukai