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

ArmedPolice ForcePaper,1,ArmedPoliceForce,3,BachelorPaper,1,BBSPaper,1,Computer,3,COVID19NEPAL,7,EPSKorea,3,ExamResults,6,ExamSchedule,6,Festivals,1,LokSewaAayog,7,LokSewaAayog ModelQuestion,1,LokSewaAayogModelQuestion,1,LokSewaAayogPaper,1,ModelQuestion,2,MSExcel,1,MSPowerPoint,1,MSWord,1,NepalArmy,3,NepalBankLimited,2,NepalElectricityAuthority,2,NepalOilCorporation,1,NepalPolice,19,NepalPolicePaper,2,NepalRastraBank,2,NepalTelecom,1,News,15,NIDNepal,2,Notes,12,QuestionCollection,7,RastriyaBanijyaBank,1,RealExamPaper,5,ShortcutKey,1,SocialSecurityFund,1,Syllabus,12,TipsTricks,3,TUUniversity,1,Vacancy,6,Valentine,1,Video,1,VisitNepal,3,
ltr
item
Online Khabar Nepal: 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
Online Khabar Nepal
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 PostsNot found any postsVIEW ALLReadmoreReplyCancel replyDeleteByHomePAGESPOSTSView AllRECOMMENDED FOR YOULABELARCHIVESEARCHALL POSTSNot found any post match with your requestBack HomeSundayMondayTuesdayWednesdayThursdayFridaySaturdaySunMonTueWedThuFriSatJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecemberJanFebMarAprMayJunJulAugSepOctNovDecjust now1 minute ago$$1$$ minutes ago1 hour ago$$1$$ hours agoYesterday$$1$$ days ago$$1$$ weeks agomore than 5 weeks agoFollowersFollowTHIS PREMIUM CONTENT IS LOCKEDSTEP 1: Share to a social networkSTEP 2: Click the link on your social networkCopy All CodeSelect All CodeAll codes were copied to your clipboardCan not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copyTable of Content