Sie sind auf Seite 1von 4

C programs printf("\nEnter the radius of the

1. Odd or Even circle:");

#include<stdio.h> scanf("%f",&rad);

#include<conio.h> area=3.14*rad*rad;

void main() circum=2*3.14*rad;

{ printf("\nArea=%f",area);

int num; printf("\nCircumference=


%f",circum);
clrscr();
getch();
printf(\n Enter the value of
num); }

scanf(%d,&num);
3. Factorial of the given
if(num%2==0) number

printf("%d is Even #include<stdio.h>


number");
void main()
else
{
printf("%d is Odd number");
int fact=1,i,num;
getch();
clrscr();
}
printf("Enter the number:");

2. Area and Circumference of scanf("%d",&num);


the circle
for(i=1;i<=num;i++)
#include<stdio.h>
{
void main()
fact=fact*i;
{
}
float rad,area,circum;

clrscr();
1
printf("The factorial of %d is {
%d",num,fact); r1 = r2 = -b/(2*a);
printf("Roots are: %.2f and %.2f", r1,
getch(); r2);
}
else
}
{
real= -b/(2*a);
imag = sqrt(-determinant)/(2*a);
printf("Roots are: %.2f+%.2fi and %.2f-
4. Prime or Not %.2fi",
#include <stdio.h> real, imag, real,
void main() imag);
{ }
int n, i, flag=0; }
printf("\nEnter a positive integer: "); 6. Fibonacci Number
scanf("%d",&n); #include<stdio.h>
for(i=2;i<=n/2;i++) #include<conio.h>
{ void main()
if(n%i==0) {
{ int f,f1=0,f2=1,i;
flag=1; clrscr();
break; printf("Enter the limit:");
} scanf("%d",&n);
} printf(\n%d\n%d,f1,f2);
if (flag==0) for(i=3;i<=n;i++)
printf("\n%d is a prime number",n); {
else f=f1+f2;
printf("\n%d is not a prime printf("\n%d",f);
number",n); f1=f2;
} f2=f;
5. Roots of quadratic equation }
#include <stdio.h> getch();
#include <math.h> }
void main()
{ 7. Sum of digits
float a, b, c, determinant, r1,r2, real, #include <stdio.h>
imag; #include <conio.h>
printf("Enter coefficients a, b and c: "); void main()
scanf("%f%f%f",&a,&b,&c); {
determinant=b*b-4*a*c; int number ,a , b=0;
if (determinant>0) printf("enter the number\n");
{ scanf( "%d", &number );
r1= (-b+sqrt(determinant))/(2*a); while(number > 0 )
r2= (-b-sqrt(determinant))/(2*a); {
printf("Roots are: %.2f and %.2f",r1 , a = number % 10;
r2); b=b+a;
} number = number / 10 ;
else if (determinant==0) }
2
printf("Sum of digits = %d", b ); 10. Armstrong Number
getch();
} #include <stdio.h>
int main()
8. Reverse a number {
#include<stdio.h> int n, n1, rem, num=0;
void main() printf("Enter a positive integer: ");
{ scanf("%d", &n);
int num,r,reverse=0; n1=n;
printf("Enter any number: "); while(n1!=0)
scanf("%d",&num); {
while(num) rem=n1%10;
{ num=num+rem*rem*rem;
r=num%10; n1/=10;
reverse=reverse*10+r; }
num=num/10; if(num==n)
} printf("%d is an Armstrong
printf("Reversed of number: number.",n);
%d",reverse); else
return 0; printf("%d is not an Armstrong
} number.",n);
}

9. Palindrome Number 11. Sorting


#include<stdio.h>
#include <stdio.h> #include<conio.h>
int main() void main()
{ {
int n, reverse=0, rem,temp; int a[10],n,i,j,temp;
printf("Enter an integer: "); clrscr();
scanf("%d", &n); printf("Enter the no of values");
temp=n; scanf("%d",&n);
while(temp!=0) printf("Enter the elements\n");
{ for(i=0;i<n;i++)
rem=temp%10; scanf("%d",&a[i]);
reverse=reverse*10+rem; for(i=0;i<n;i++)
temp/=10; {
} for(j=i+1;j<n;j++)
if(reverse==n) {
printf("%d is a palindrome.",n); if(a[i]>a[j])
else {
printf("%d is not a palindrome.",n); temp=a[i];
return 0; a[i]=a[j];
} a[j]=temp;
}
}
}

3
printf("\n Ascending order"); for(j=1;j<=col1;j++)
for(i=0;i<n;i++) {
printf("\t%d",a[i]); scanf("%d",&a[i][j]);
printf("\n Descending order"); }
for(i=n-1;i>=0;i--) }
printf("\t%d",a[i]); printf("Enter the values of second
getch(); matrix\n");
} for(i=1;i<=row2;i++)
{
12. MATRIX ADDITION for(j=1;j<=col2;j++)
#include<stdio.h> {
#include<conio.h> scanf("%d",&b[i][j]);
void main() }
{ }
int a[5][5],b[5][5],c[5][5]; for(i=1;i<=row1;i++)
int row1,row2,col1,col2,i,j,k; {
clrscr(); for(j=1;j<=col1;j++)
printf("Enter the row value of first {
matrix\n"); c[i][j]=a[i][j]+b[i][j];
scanf("%d",&row1); }
printf("Enter the column value of first }
matrix\n"); printf("Sum of the two matrix is\n");
scanf("%d",&col1); for(i=1;i<=row1;i++)
{
printf("Enter the row value of second for(j=1;j<=col1;j++)
matrix\n"); {
scanf("%d",&row2); printf("%d\t",c[i][j]);
printf("Enter the column value of }
second printf("\n");
matrix\n"); }
scanf("%d",&col2); }
if((row1==row2)&&(col1==col2)) else
{ printf("Addition cannot be
printf("Matrix can be added \n"); perform");
printf("Enter the values of first getch();
matrix\n"); }
for(i=1;i<=row1;i++)
{

Das könnte Ihnen auch gefallen