Introduction To Programming: Mridul 291/COE/14 Coe 2
Introduction To Programming: Mridul 291/COE/14 Coe 2
Introduction To Programming: Mridul 291/COE/14 Coe 2
PROGRAMMING
MRIDUL
291/COE/14
COE 2
S.No
.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
14.
15.
16.
17.
12.
13.
18.
19.
COE 2
MRIDUL
Date
Pag
e
No.
Remark
s
291/COE/14
COE 2
MRIDUL
291/COE/14
SOURCE CODE
#include<stdio.h>
int main()
{
int a,sum=0;
printf(Enter an integer);
scanf(%d,&a);
while(a>0)
{
sum+=a%10;
a/=10;
}
printf(Sum of digits of integer is %d.,sum);
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
return 0;}
OUTPUT
MRIDUL
291/COE/14
FLOWCHART
SOURCE CODE
#include<stdio.h>
COE 2
MRIDUL
291/COE/14
int main()
{
int a,b,c,max;
printf(Enter three integers:);
scanf(%d%d%d,&a,&b,&c);
max=a;
if(max<b)
max=b;
if(max<c)
max=c;
printf(Greatest among three integers is %d.,max);
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<math.h>
long fact(int i)
{
if(i!=0)
COE 2
MRIDUL
291/COE/14
return i*fact(i-1);
else
return 1;
}
void main()
{
int i;
float x, y, sum=0, temp;
clrscr();
printf("Enter angle in degrees\n");
scanf("%f", &x);
y=x*3.1415/180;
for(i=1;i<=15;i=i+2)
{
temp=pow(y,i)/fact(i)*pow(-1,((i-1)/2));
sum=sum+temp;
}
printf("value of sin(%f) is %f\n", x, sum );
getch();
}
OUTPUT
MRIDUL
291/COE/14
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main() {
float a, b, c, D ,x1, x2, rp , ip;
printf("\nEnter the coefficients of quadratic equation in the form of
ax^2+bx+c = \n");
scanf("%f %f %f", &a, &b,&c);
D=b*b-4*a*c;
if(D>=0) {
x1= (-b+sqrt(D))/(2*a);
x2= (-b-sqrt(D))/(2*a);
printf("The roots are %f %f", x1, x2);
}
else {
rp=b/(2*a);
ip=sqrt(-D)/(2*a);
printf("The roots are %f +i%f ,%f -i%f", rp, ip, rp,ip);
}
return 0 ;
getch();
}
OUTPUT:
COE 2
MRIDUL
291/COE/14
SOURCE CODE
#include<stdio.h>
COE 2
MRIDUL
291/COE/14
#include<conio.h>
void main()
{
int num, num1;
long fact=1;
clrscr();
printf("Enter any number\n");
scanf("%d",&num);
num1=num;
while(num>0)
{
fact=fact*num;
num--;
}
printf("Factorial of %d is %ld", num1, fact);
getch();
}
OUTPUT
COE 2
MRIDUL
291/COE/14
int ch;
do
{
printf("\nEnter The Numbers :");
scanf("%f%f",&a,&b);
printf("\t\tMenu\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit\nEnter
Your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("The Sum Is :%f\n",a+b);
break;
case 2:printf("The Diff. Is :%f\n",a-b);
break;
case 3:printf("The Product Is :%f\n",a*b);
break;
case 4: if(b!=0)
printf("The Result Is :%f\n",a/b);
else
printf("Try Again!! ");
break;
case 5:exit(0);
default :printf("Wrong Choice!!!!!\n");
}
}while(1);
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
COE 2
MRIDUL
291/COE/14
SOURCE CODE
#include<stdio.h>
int main()
{
int a,b,c,max;
COE 2
MRIDUL
291/COE/14
COE 2
MRIDUL
291/COE/14
while(n)
{
p*=(n%10);
n/=10;
}
printf("%d",p);
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
scanf("%d",&n);
int a[n],i,sum=0;
printf("Enter the numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
printf("Sum of the numbers entered is %d",sum);
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
scanf("%d", &n);
printf("Enter numbers\n");
for(i=0;i<n;i++)
scanf("%d", &a[i]);
for(i=0;i<n-1;i++)
{for(j=i+1;j<n;j++)
{if(a[i]>a[j])
{temp=a[i];
a[i]=a[j];
a[j]=temp;}}}
printf("\nAscending Order\n");
for(i=0;i<n;i++)
printf("%d\t", a[i]);
printf("\nDescending Order\n");
for(i=n-1;i>-1;i--)
printf("%d\t", a[i]);
getch();
}
OUTPUT
COE 2
MRIDUL
291/COE/14
COE 2
MRIDUL
291/COE/14
{
scanf("%f",&a[i]);
sum+=a[i];
}
printf("Sum is %g.\n",sum);
avg=sum/n;
printf("Average is %g.\n",avg);
sum=0;
for(i=0;i<n;i++)
{
a[i]=pow((a[i]-avg),2);
sum+=a[i];
}
avg=sum/n;
sd=sqrt(avg);
printf("Standard deviation is %g.\n",sd);
return 0;
}
OUTPUT
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
for(i=1;i<=10;i++)
{ for(j=1;j<=5;j++)
printf("%d * %d = %d\t", j,i,i*j);
}
printf("\n");
getch();
}
COE 2
MRIDUL
291/COE/14
OUTPUT
COE 2
MRIDUL
291/COE/14
c[i][j]=a[i][j]+b[i][j];
printf("Sum of the two matrices entered is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d ",c[i][j]);
}
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
COE 2
MRIDUL
291/COE/14
for(j=0;j<n;j++)
c[i][j]=a[i][j]-b[i][j];
printf("Difference of the two matrices entered is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d ",c[i][j]);
}
return 0;
}
OUTPUT
COE 2
MRIDUL
291/COE/14
COE 2
MRIDUL
291/COE/14
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]+=a[i][k]*b[k][j];
}
printf("Product of the two matrices entered is\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("%d ",c[i][j]);
}
}
return 0;}
OUTPUT
COE 2
MRIDUL
291/COE/14
OUTPUT
COE 2
MRIDUL
291/COE/14
if(n==1||n==2)
return 1;
return fib(n-1)+fib(n-2);
}
int main()
{
int n,x;
printf("Enter the value of n:");
scanf("%d",&n);
if(n>=1)
{
x=fib(n);
printf("%dth Fibonacci no. is %d.",n,x);
}
else
printf("Fibonacci no. does not exist.");
return 0;
}
COE 2
MRIDUL
291/COE/14
OUTPUT
COE 2
MRIDUL
291/COE/14