Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prorgrams #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sem1/C_Programming/10fibofact.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*Write a Menu Driven C Program to implement the following using recursion
a. Factorial of a number
b. Fibonacci series
*/
#include<stdio.h>
int main()
{
int fibo[10],i,ch,n,fact=1;
printf("1.Factorial of a number\n2.Fibonacci series\nenter your choice");
scanf("%d",&ch);
switch(ch){
case 1:
{
printf("Enter the number to factorial\n");
scanf("%d",&n);
//printf("n=%d",n);
for(i=n;i>0;i--)
fact*=i;
printf("Factorial of %d=%d\n",n,fact);
break;
}
case 2:
{
printf("Enter the number to fibonaci series\n");
scanf("%d",&n);
fibo[0]=0;fibo[1]=1;
for(i=2;i<=n;i++)
fibo[i]=fibo[i-2]+fibo[i-1];
printf("Fibonaci series\n");
for(i=0;i<n;i++)
printf("%d\n",fibo[i]);
break;
}
}
return 0;
}
35 changes: 35 additions & 0 deletions Sem1/C_Programming/11compaddsub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
void add();
void sub();
struct compl
{
int img;
int real;
};
void main()
{

int i;
printf("enter the real & img no\n");
struct compl cn[2];
for(i=0;i<2;i++)
{
scanf("%d%d",&cn[i].real,&cn[i].img);
}
add(cn);
sub(cn);
}
void add(struct compl cn[])
{
int real1,img1;
real1=cn[0].real+cn[1].real;
img1=cn[0].img+cn[1].img;
printf("sum of complex no:%d+%di\n",real1,img1);
}
void sub(struct compl cn[])
{
int real1,img1;
real1=cn[0].real-cn[1].real;
img1=cn[0].img-cn[1].img;
printf("diff of complex no:%d+%di\n",real1,img1);
}
34 changes: 34 additions & 0 deletions Sem1/C_Programming/8magicmatrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//Write a C program to implement a magic square of size n.
#include<stdio.h>
int main()
{
int ord,i,j,a[10][10],dig1=0,dig2=0;
printf("enter order of matrix(should be square matrix)\n");
scanf("%d", &ord);
printf("Enter the elements\n");
for(i=0;i<ord;i++)
{
for(j=0;j<ord;j++)
{
scanf("%d",&a[i][j]);
}
}
//for 1st dialgonal
for(i=0;i<ord;i++)
{
for(j=0;j<ord;j++)
{
if(i==j)
dig1+=a[i][j];
if(i+j==ord-1)
dig2+=a[i][j];
}
}
if((dig1==dig2))
printf("Magic matrix");
else
printf("Not magic matrix");


return 0;
}
66 changes: 66 additions & 0 deletions Sem1/C_Programming/9addint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*Write a Menu driven C program to
a. Accept two numbers n and m
b. Sum of all integers ranging from n to m
c. Sum of all odd integers ranging from n to m
d. Sum of all even integers ranging from n to m
Display an error message if n > m. Create functions for each of the options
*/
#include<stdio.h>
void sum1(int m,int n);
void sum2(int m,int n);
void sum3(int m,int n);
int i;
int main()
{
int m,n,ch;
printf("1.sum of all integers\n2.sum of all odd integers\n3.sum of all even integers\nenter your choice\n");
scanf("%d",&ch);
read:
printf("enter m and n values\n");
scanf("%d %d",&m,&n);
if(m>n)
{
printf("please re-enter values\n");
goto read;
}
switch(ch)
{
case 1:
sum1(m,n);
break;
case 2:
sum2(m,n);
break;
case 3:
sum3(m,n);
break;
default:
printf("invalid choice");
break;
}

return 0;
}

void sum1(int m, int n)
{ int sum=0;
for(i=m;i<=n;i++)
sum=sum+i;
printf("Sum of all integers are %d\n",sum);
}
void sum2(int m, int n)
{
int sum=0;
for(i=m;i<=n;i++)
{if(i%2==1)
sum=sum+i;}
printf("Sum of all odd integers are %d\n",sum);
}
void sum3(int m, int n)
{
int sum=0;
for(i=m;i<=n;i++)
{if(i%2==0)
sum=sum+i;}
printf("Sum of all even integers are %d\n",sum);
}