C Programming Part 2

C Programming Notes

C Programming:

1) Fibonacci
2) To convert Lower case letters into Upper case letters
3) Arranging in ascending order
4) Transpose of Matrix




/* Fibonacci series */ 
/* Program Coded By Chetan Thapa Magar */ 

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i;
printf("Enter the terms to generate:\t");
scanf("%d", &n);
for(i=1; i<=n; i++)
printf("\n%d", fib(i));
getch();
}
int fib(int x)
{
if(x==1)
return 0;
else
if(x==2)
return 1;
else
return (fib(x-1)+fib(x-2));
}

Output / Execution:
Enter the terms to generate: 7
0
1
1
2
3
5
8

/* To convert Lower case letters into Upper case letters */ 
/* Program Coded By Chetan Thapa Magar. */ 

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char a[50], b[50];
int i;
clrscr();
puts("Enter the string:\t");
gets(a);
for(i=0; a[i]!='\0'; i++)
b[i]=toupper(a[i]);
b[i]='\0';
printf("\nThe upper case string is %s\t", b);
getch();
}

Output / Execution:
Enter the string: chetan thapa magar
The upper case string is: CHETAN THAPA MAGAR


/* Insertion sort */ 
/* Program Coded By Chetan Thapa Magar */ 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20], n, temp, i, j;
clrscr();
printf("Enter the number of terms:\n");
scanf("%d", &n);
printf("\nEnter the elements for the array:\n");
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=1; i<n; i++)
{
temp=a[i];
j=i-1;
while(temp<a[j] && j>=0)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("\nThe ascending order for the given array is:\n\t");
for(i=0; i<n; i++)
printf("\n%d", a[i]);
getch();
}

Output / Execution:
Enter the number of terms:
5

Enter the elements for the array:
2617
2605
2609
2632
2610

The ascending order for the given array is:

2605
2609
2610
2617
2632


/* Transpose of Matrix */ 
/* Program Coded By Chetan Thapa Magar */ 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[9][9], i, j, d=1;
printf("Enter the matrix values:\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
scanf("%d", &a[i][j]);
}
printf("\nThe transpose of the given matrix is:\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
printf("\t\t%d", a[j][i]);
printf("\n");
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
if(i==j)
d=d*a[i][j];
}
}
printf("\nThe diagonal value is %d", d);
getch();
}

Output / Execution:

Enter the matrix values:
1
2
3
4
5
6
7
8
9

The transpose of the given matrix is:

1 4 7
2 5 8
3 6 9


The diagonal value is 45 

COMMENTS

BLOGGER
Name

ArmedPoliceForce,5,ArmedPoliceForcePaper,1,BachelorPaper,1,BBSPaper,1,Computer,6,COVID19NEPAL,7,CProgramming,2,EPSKorea,3,ExamResults,8,ExamSchedule,4,Excel,1,Festivals,1,Hardware,1,LokSewaAayog,9,LokSewaAayogModelQuestion,2,LokSewaAayogPaper,1,ModelQuestion,3,NepalArmy,3,NepalBankLimited,2,NepalElectricityAuthority,2,NepalOilCorporation,1,NepalPolice,20,NepalPolicePaper,2,NepalRastraBank,2,NepalTelecom,1,News,23,NIDNepal,2,Notes,14,PowerPoint,1,QuestionCollection,7,RastriyaBanijyaBank,1,RealExamPaper,5,ShortcutKey,1,SocialSecurityFund,1,Syllabus,12,TipsTricks,3,TUUniversity,1,University,4,Vacancy,6,Valentine,1,Video,1,VisitNepal,3,Word,1,
ltr
item
Chetan Thapa Magar: C Programming Part 2
C Programming Part 2
C Programming Notes
https://1.bp.blogspot.com/-FmWLPjDEUNA/XtCUbtB1xmI/AAAAAAAABOs/K7Dtkoua3ossuwWPC-CbHoXbH0ik6N8cACPcBGAYYCw/s200/Part%2B2.jpg
https://1.bp.blogspot.com/-FmWLPjDEUNA/XtCUbtB1xmI/AAAAAAAABOs/K7Dtkoua3ossuwWPC-CbHoXbH0ik6N8cACPcBGAYYCw/s72-c/Part%2B2.jpg
Chetan Thapa Magar
https://www.chetanthapamagar.com.np/2020/05/c-programming-part-2.html
https://www.chetanthapamagar.com.np/
https://www.chetanthapamagar.com.np/
https://www.chetanthapamagar.com.np/2020/05/c-programming-part-2.html
true
2012862999246101061
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy