Professional Documents
Culture Documents
printf(" %d is greater",c);
getch();
}
{
int a,b,c,d;
float r1,r2;
clrscr();
printf("Enter the co-efficient values a, b, c : ");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
printf("The roots are imaginary.");
else if(d==0)
{
r1=-b/(2*a);
r2=r1;
printf("The roors are equal r1=%4.2f r2=
%4.2f",r1,r2);
}
else
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("The roors are different r1=%4.2f r2=
%4.2f",r1,r2);
}
getch();
}
m2=m1+1;
y2=y1;
}
else if((d1==31) && (m1==12))
{
d2=1;
m2=1;
y2=y1+1;
}
else if((d1==31) && (m1!=12))
{
d2=1;
m2=m1+1;
y2=y1;
}
else if((d1==29) && (m1==2) && (y1%4==0))
{
d2=1;
m2=3;
y2=y1;
}
else if((d1==28) && (m1==2) && (y1%4!=0))
{
d2=1;
m2=3;
y2=y1;
}
else
{
d2=d1+1;
m2=m1;
y2=y1;
}
printf("Tomorrow's date is (%d/%d/%d)",d2,m2,y2);
getch();
}
else
{
if(d1==30)
{
d2=1;
m2=m1+1;
y2=y1;
}
else
{
d2=d1+1;
m2=m1;
y2=y1;
}
}
printf("Tomorrows date is : %d / %d /%d
\n",d2,m2,y2);
getch();
}
2. Manipulating Numbers.
2.1 Sum of individual digits of a number
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n,num,sum,a;
clrscr();
printf("Enter the number : ");
scanf("%d",&num);
sum=0;
n=num;
while(n>0)
{
a=n%10;
sum=sum+a;
n=n/10;
}
printf("The sum of individual digits of %d is
%d",num,sum);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n,num,rev,a;
clrscr();
printf("Enter the number : ");
scanf("%d",&num);
rev=0;
n=num;
while(n>0)
{
a=n%10;
rev=rev*10+a;
n=n/10;
}
printf("The reverse of %d is %d",num,rev);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n,num,arm,a;
clrscr();
printf("Enter the number : ");
scanf("%d",&num);
arm=0;
n=num;
while(n>0)
{
a=n%10;
arm=arm+pow(a,3);
n=n/10;
}
if(num==arm)
printf("The number %d is armstrong",num);
else
printf("The number %d is not armstrong",num);
getch();
}
}
printf("The digit %d is found %d times in
%d",d,count,num);
getch();
}
{
int i,n,sum;
clrscr();
printf("Enter the value of N : ");
scanf("%d", &n);
sum=0;
for( i=1;i<=n;i++)
sum+=i;
printf("The sum of first %d numbers is :
%d",n,sum);
getch();
}
clrscr();
printf("Enter the values of x and n : ");
scanf("%f%f",&x,&n);
sum=0.0;
s=1;
for(i=1;i<=n;i+=2)
{
s=s*-1;
sum=sum+((pow(x,i)/fact(i))*s);
}
printf("\nThe sum of series %2.0f ^ %2.0f is :
%f",x,n,sum);
getch();
}
4. Generate Numbers
4.1 Generate Multiples of a Number
#include<stdio.h>
#include<conio.h>
main()
{
int i,n;
clrscr();
printf("Enter the number : ");
scanf("%d",&n);
printf("The Multiples of %d are : \n",n);
for( i=n;i<=50;i+=n)
printf("%5d",i);
getch();
}
{
prime=1;
for(j=2;j<i;j++)
{
if(i%j==0)
{
prime=0;
break;
}
}
if(prime==1)
printf("%5d", i);
}
getch();
}
{
a=n%8;
oct=oct+(pow(10,i)*a);
n=n/8;
i++;
}
printf("The Octal equivalent of %ld is %ld
",num,oct);
getch();
}
int bin(int n)
{
int i,a,m;
m=0;
i=0;
while(n>0)
{
a=n%2;
m=m+a*pow(10,i);
n=n/2;
i++;
}
return m;
}
void main()
{
int dec,gray,a;
//float sum,n,x;
clrscr();
printf("Enter the Decimal number : ");
scanf("%d",&dec);
a=dec >> 1;
gray=dec ^ a;
printf("The gray equivalent of %d is
%d",bin(dec),bin(gray));
getch();
}
i--;
dec=d[i]*pow(10,i);
a=d[i];
do
{
a=a^d[i-1];
dec=dec+(a*pow(10,i-1));
i--;
}while(i>0);
printf("The binary equivalent of gray code %d is
%d",gray, dec);
getch();
}
getch();
}
if(num==a[i])
{
found=1;
pos=i;
break;
}
if(found)
printf("\nThe number %d is found at position %d
of the list.\n",num,pos+1);
else
printf("\nThe number %d is not found in the
list.\n",num);
getch();
}
{
char *str,i,j,len;
clrscr();
printf("Enter the string .. : ");
scanf("%s",str);
i=0;
j=strlen(str)-1;
len=j;
/* while((i<j) && (str[i]==str[j]))
{
i++; j--;
}
*/
for(i=0,j=len;(i<j) && (str[i]==str[j]);i++,j--)
{
}
if(i<j)
printf("The string %s is not palindrome",str);
else
printf("The string %s is palindrome",str);
getch();
}
rev[i]=str[j];
i++;j--;
}
rev[i]='\0';
return rev;
}
int equal(char *s1, char *s2)
{
int i,len;
if(getlength(s1)!=getlength(s2))
return 0;
len=getlength(s1);
i=0;
while((i<len) && (s1[i]==s2[i]))
{
i++;
}
if(i<len)
return 0;
return 1;
}
void main()
{
char *str1,*str2,i,j,len;
clrscr();
printf("Enter the string - 1 : ");
scanf("%s",str1);
printf("Enter the string - 2 : ");
scanf("%s",str2);
if(equal(str1,str2))
printf("\nThe strings %s and %s are
equal\n",str1,str2);
else
printf("The strings %s and %s are not
equal\n",str1,str2);
printf("\n The reverse of %s is
%s\n",str1,reverse(str1));
printf("\n The reverse of %s is
%s\n",str2,reverse(str2));
getch();
}
scanf("%d",&e[i].eno);
printf("\nEnter Employee Name : ");
scanf("%s",&e[i].ename);
printf("\nEnter Basic Salary : ");
scanf("%ld",&e[i].basic);
e[i].da=(e[i].basic*35)/100;
e[i].hra=(e[i].basic*8)/100;
e[i].ta=(e[i].basic*5)/100;
e[i].pf=(e[i].basic*10)/100;
e[i].lic=(e[i].basic*3)/100;
e[i].itax=(e[i].basic*2)/100;
e[i].gross=e[i].basic+e[i].da+e[i].hra+e[i].ta;
e[i].ded=e[i].pf+e[i].lic+e[i].itax;
e[i].netpay=e[i].gross-e[i].ded;
}
for(i=0;i<n;i++)
{
printf("\n==============================
=========\n");
printf("\t PAY SLIP No : %d",i+1);
printf("\n---------------------------------------\n");
printf(" EMP_No : %d",e[i].eno);
printf("\tNAME : %s",e[i].ename);
printf("\n---------------------------------------\n");
printf(" BASIC : %8.2f",(float)e[i].basic);
printf("\n---------------------------------------\n");
printf(" DA : %8.2f",e[i].da);
printf("\tPF : %7.2f\n",e[i].pf);
printf(" HRA : %8.2f",e[i].hra);
printf("\tLIC : %7.2f\n",e[i].lic);
printf(" T.A. : %8.2f",e[i].ta);
printf("\tITAX : %7.2f",e[i].itax);
printf("\n---------------------------------------\n");
printf(" GROSS : %8.2f",e[i].gross);
printf(" DEDUCTION : %7.2f",e[i].ded);
printf("\n==============================
=========\n");
printf("\t\tNETPAY : Rs. %8.2f",e[i].netpay);
printf("\n==============================
=========\n\n");
}
getch();
}
OUTPUTL:
Enter No of Employees : 2
{
int rno;
char name[20];
int m1, m2,m3;
float tot, avg;
char grade;
}s[10];
void main()
{
int i,n;
char c;
clrscr();
printf("Enter No of students : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n\tEnter details of Student : %d\n\n",i+1);
printf("Enter Student No : ");
scanf("%d",&s[i].rno);
printf("Enter Student Name : ");
scanf("%s",s[i].name);
printf("Enter Mark - 1 : ");
scanf("%d",&s[i].m1);
printf("Enter Mark - 2 : ");
scanf("%d",&s[i].m2);
printf("Enter Mark - 3 : ");
scanf("%d",&s[i].m3);
s[i].tot=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].tot/3;
if((s[i].m1<45)||(s[i].m2<45)||(s[i].m3<45))
s[i].grade='U';
else if(s[i].avg>=75)
s[i].grade='S';
else if(s[i].avg>=60)
s[i].grade='A';
else if(s[i].avg>=45)
s[i].grade='B';
else
s[i].grade='U';
}
printf("\n--------------------------------------------------------------------\n");
printf("\t\t\tSTUDNET MARK DETAILS");
printf("\n--------------------------------------------------------------------\n");
Student No : 22
Student Name : Ganesh.B
Mark - 1
: 67
Mark - 2
: 56
Mark - 3
: 89
Student No : 33
Student Name : Sam
Mark - 1
: 89
Mark - 2
: 80
Mark - 3
: 97
Enter Student No : 43
Enter
Enter
Enter
Enter
Student No : 34
Student Name : Subha
Mark - 1
: 89
Mark - 2
: 83
Mark - 3
: 87