Professional Documents
Culture Documents
#include<stdio.h>
#include<conio.h>
void main ()
{
int a, b, c;
clrscr();
printf("Enter the value of a,b,c");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
{
printf("A is greater");
}
else if((b>c)&&(b>a))
{
printf("B is greater");
}
else
printf("C is greater");
getch();
}
OUT PUT:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,sum=0;
clrscr();
while(i<=10)
{
sum=sum+i;
i++;
}
printf("The sum of numbers upto 10 is %d",sum);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,real,imag,r1,r2,n;
int k;
clrscr();
printf("Enter the numbers");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
k=1;
if(d==0)
k=2;
if(d>0)
k=3;
switch(k)
{
case 1:
{
printf("Roots are imaginary\n");
real=-b/(2*a);
d=-d;
n=pow((double)d,(double)0.5);
imag=n/(2*a);
printf("r1=%7.2f+j%7.2f\n",real,imag);
printf("r2=%7.2f-j%7.2f\n",real,imag);
break;
}
case 2:
{
printf ("roots are real and equal\n");
r1=-b/(2*a);
printf("r1=r2%7.2f\n",r1);
break;
}
case 3:
{
printf("real and unequal roots\n");
r1=(-b+sqrt((double)d)/(2*a));
r2=(-b-sqrt((double)d)/(2*a));
printf("r1=%7.2f\n",r1);
printf("r2=%7.2f\n",r2);
break;
}
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i,w,s=0,p=2;
clrscr();
printf("ENTER A VALUE FOR N: " ,n);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
w=(pow(i,p));
s=s+w;
}
printf("SUM OF SERIES: %d",s);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("\n\nENTER THE NUMBER ");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
printf("\n THE GIVEN NUMBER IS NOT A PRIME NUMBER");
goto exit;
}
}
printf("\nTHE GIVEN NUMBER IS A PRIME NUMBER");
exit:getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m,n,sum=0,l;
clrscr();
printf("ENTER THE NUMBER: ");
scanf("%d",&m);
l=m;
while(m!=0)
{
n=m%10;
sum=sum+pow(n,3);
m=m/10;
}
if(l==sum)
printf("\n %d IS AN AMSTRONG NUMBER",l);
else
printf("\n%d IS NOT AN AMSTRONG NUMBER",l);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
void main()
{
void fibo(void);
clrscr();
fibo();
getch();
}
void fibo()
{
int n,i,l,j,s;
printf("Enter the value n=");
scanf("%d",&n);
i=0;
j=1;
s=0;
l=0;
printf("%d\n",i);
printf("%d\n",j);
while(l<=n-3)
{
s=i+j;
printf("\n%d",s);
i=j;
j=s;
l++;
}
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
int fact=1;
int facto(int n)
{
fact*=n;
if(n>1)
return(facto(n-1));
else
return(fact);
}
void main()
{
int m,facti;
clrscr();
printf("\nENTER VALUE TO FIND THE FACTORIAL: ");
scanf("%d",&m);
facti=facto(m);
printf("\nTHE FACTORIAL VALUE: %d",facti);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m,n,rev=0,l;
clrscr();
printf("ENTER THE NUMBER: ");
scanf("%d",&m);
l=m;
while(m!=0)
{
n=m%10;
rev=(rev*10)+n;
m=m/10;
}
if(l==rev)
printf("\n%d IS A PALINDROME",l);
else
printf("\n%d IS NOT A PALINDROME",l);
getch();
}
OUTPUT
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],b=0,i,n;
clrscr();
printf("Enter the limit: ");
scanf("%d",&n);
printf("Enter the numbers: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
b=b+a[i];
}
printf("The sum of the array is %d",b);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int len,pal=1;
int i=0;
clrscr();
printf("Enter the string: ");
scanf("%s",str);
len=strlen(str);
while(i<len)
{
if(str[i]!=str[(len-1)-i])
{
pal=0;
break;
}
else
{
i++;
}
}
if(pal==1)
{
printf("\nThe given string is a palindrome");
}
else
{
printf("\nThe given string is not a palindrome");
}
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],k,i,j;
clrscr();
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
int regno;
char name[20];
int per;
char cla[10];
}s[10];
void main()
{
int i,n;
clrscr();
printf("Enter the number of the students: \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Reg. No, Name, Percentage: \n");
scanf("%d%s%d",&s[i].regno,&s[i].name,&s[i].per);
}
for(i=0;i<n;i++)
{
if(s[i].per>60)
strcpy(s[i].cla,"FIRST CLASS");
else if(s[i].per>45&&s[i].per<60)
strcpy(s[i].cla,"SECOND CLASS");
else
strcpy(s[i].cla,"FAIL");
}
for(i=0;i<n;i++)
{
printf("%d\t%s\t%d\t%s\n",s[i].regno,s[i].name,s[i].per,s[i].cla);
printf("-----------------------------------------------------------------------\n");
}
getch();
}
OUTPUT:
002
ASHOK
52
003
SUREN
40
#include<stdio.h>
#include<conio.h>
void main()
{
union result
{
int marks;
char grade;
};
struct res
{
char name[15];
int age;
union result perf;
}data;
clrscr();
printf("Size of union:%d\n",sizeof(data.perf));
printf("Size of structure:%d\n",sizeof(data));
getch();
}
OUTPUT:
Size of union: 2
Size of structure: 19
PROGRAM FOR MEMORY ALLOCATION
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<alloc.h>
#include<fstream.h>
#define NULL0
void main()
{
char*buffer;
clrscr();
//if(buffer==(char*)malloc(10)==NULL)
{
//printf("\nmemory allocation failed");
//exit(0);
}
printf("\nBuffer of size %d is created\n",sizeof(buffer));
strcpy(buffer,"bombay");
printf("\nBuffer contains:%s",buffer);
if(buffer==(char*)realloc(buffer,15)==NULL)
{
printf("\nreallocation failed");
exit(0);
}
printf("\nBuffer size is modified");
printf("\nBuffer still contains:%s",buffer);
strcpy(buffer,"mumbai");
printf("\nBuffer now contains:%s",buffer);
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
void swapping(int,int);
void main()
{
int a,b,c;
clrscr();
printf("\nProgram to swap two numbers\n");
printf("\nEnter the values of A and B: ");
scanf("%d%d",&a,&b);
printf("\nBefore Swapping A=%d,B=%d",a,b);
swapping(a,b);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nProgram to swap two numbers\n");
printf("\nEnter the values of A and B: ");
scanf("%d%d",&a,&b);
printf("\nBefore Swapping A=%d,B=%d",a,b);
swapping(&a,&b);
getch();
}
void swapping(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
printf("\nAfter Swapping A=%d,B=%d",*x,*y);
}
OUTPUT: