0% found this document useful (0 votes)
2 views1 page

Programs

The document contains multiple C programming code snippets for various tasks including checking for prime numbers, generating Fibonacci sequences, summing matrix elements, finding the largest/smallest elements in an array, calculating GCD using recursion, checking for palindromes, and computing factorials. Each code snippet is structured with main functions and relevant logic to perform the specified operations. Additionally, there are examples of data structures like student records and a switch case for month names.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Programs

The document contains multiple C programming code snippets for various tasks including checking for prime numbers, generating Fibonacci sequences, summing matrix elements, finding the largest/smallest elements in an array, calculating GCD using recursion, checking for palindromes, and computing factorials. Each code snippet is structured with main functions and relevant logic to perform the specified operations. Additionally, there are examples of data structures like student records and a switch case for month names.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prime no.

Fibonacci Sum of elements of matrix


#include<stdio.h> #include<stdio.h> #include<stdio.h>
void main() void main() void main()
{ { {
int n,i,flag=0; int n,i,a=0,b=1,c; int a[50][50],i,j,sum=0,r,c;
printf("enter a no\n"); printf("Enter no of terms to be printed\n"); printf("enter dimensions of matrix\n");
scanf("%d",&n); scanf("%d",&n); scanf("%d%d",&r,&c);
for(i=2;i<=n/2;i++) if(n==1) printf("enter elements of matrix\n");
{ printf("%d",a); for(i=0;i<r;i++){
if(n%i==0) else if(n==2) for(j=0;j<c;j++){
{ printf("%d %d ",a,b); scanf("%d",&a[i][j]);
flag=1; else{ sum=sum+a[i][j];}}
break; printf("%d %d ",a,b); printf("The entered matrix is:\n");
} for(i=1;i<=n-2;i++){ for(i=0;i<r;i++){
} c=a+b; for(j=0;j<c;j++){
if(flag==1) printf("%d ",c); printf("%d\t",a[i][j]);}
printf("Not a Prime No"); a=b; printf("\n");}
else b=c;}} printf("Sum of the entered matrix is %d",sum);
printf("Prime No"); } }
}
Fibonacci recursion Largest/smallest(use min, change sign) of 1D array
Addition of 2 matrices #include<stdio.h> #include<stdio.h>
#include<stdio.h> int a=0,b=1; void main()
void main() void fibo(int n); {
{ void main(){ int a[50],max,i,n,temp;
int x[10][10],y[10][10],z[10][10],i,j,r,c; int n; printf("enter no of elements\n");
printf("enter dimensions of matrix\n"); printf("enter no of terms\n"); scanf("%d",&n);
scanf("%d%d",&r,&c); scanf("%d",&n); printf("enter elements\n");
printf("enter elements of 1st matrix\n"); if(n==1){ for(i=0;i<n;i++){
for(i=0;i<r;i++){ printf("%d",a);} scanf("%d",&a[i]);}
for(j=0;j<c;j++){ else{ max=a[0];
scanf("%d",&x[i][j]);}} printf("%d %d ",a,b); for(i=0;i<n;i++){
printf("enter elements of 2nd matrix\n"); fibo(n-2);}} if(max<a[i]){
for(i=0;i<r;i++){ void fibo(int n){ max=a[i];}}
for(j=0;j<c;j++){ int c; printf("Largest element of the array is %d",max);
scanf("%d",&y[i][j]);}} if(n>0){ }
for(i=0;i<r;i++){ c=a+b;
for(j=0;j<c;j++){ printf("%d ",c); Name, roll no, fees
z[i][j]=x[i][j]+y[i][j];}} a=b; #include<stdio.h>
printf("addition of two matrices is\n"); b=c; struct student{
for(i=0;i<r;i++){ fibo(n-1);}} char name[50];
for(j=0;j<c;j++){ int roll;
printf("%d\t",z[i][j]);} GCD recursion int fees;};
printf("\n");}} #include<stdio.h> void main(){
int gcd(int a,int b) struct student a[50];
{ int n,i;
String palindrome if(b==0){ printf("Enter no of students\n");
#include<stdio.h> return a;} scanf("%d",&n);
#include<string.h> else{ for(i=0;i<n;i++){
void main() return gcd(b,a%b);} printf("Enter Name\n");
{ } scanf("%s",&a[i].name);
char str[50],len,i,flag=0; void main() printf("Enter Roll no\n");
printf("Enter a string\n"); { scanf("%d",&a[i].roll);
gets(str); int a,b; printf("Enter Fees\n");
len=strlen(str); printf("Enter two nos\n"); scanf("%d",&a[i].fees);}
for(i=0;i<len/2;i++){ scanf("%d%d",&a,&b); printf("Name\tRollNo\tFees\n");
if(str[i]!=str[len-1]){ printf("GCD is %d",gcd(a,b)); printf("-------------------------\n");
flag=1; } for(i=0;i<n;i++){
break;} printf("%s\t",a[i].name);
len--;} * printf("%d\t",a[i].roll);
if(flag==1) ** printf("%d\n",a[i].fees);}}
printf("Not a Palindrome\n"); ***
else **** Implement birth name using no
printf("Palindrome\n"); #include<stdio.h> #include<stdio.h>
} void main() void main()
{ {
int n,i,j,k; int n;
Recursion factorial printf("enter no of rows\n"); printf("Enter month no\n");
#include<stdio.h> scanf("%d",&n); scanf("%d",&n);
int fact(int n){ for(i=1;i<=n;i++){ switch(n){
if(n==0) for(k=1;k<=n-i;k++){ case 1: printf("January");
return 1; printf(" ");} break;
else for(j=1;j<=i;j++){ case 2: printf("February");
return n*fact(n-1);} printf("*"); break;
void main(){ } case 3: printf("March");
int n; printf("\n"); break;
printf("enter a no\n"); } ||till 12
scanf("%d",&n); } default: printf("Enter valid input\n");}
printf("FACTORIAL= %d",fact(n));} }

You might also like