Posts

Showing posts from December, 2010

C Program To Take Input A 2D Array Of 2x5 In Column Major Order

♣ Try it Out :: #include<stdio.h> #include<conio.h> #define row 2 #define col 5 main() { int arr[row][col], i, j; printf("Enter a 2x5 matrix in column major order: \n\n"); for(i=0; i<col; i++) for(j=0; j<row; j++) scanf("%d", &arr[j][i]); printf("\nYou have entered: \n\n"); for(i=0; i<row; i++) { for(j=0; j<col; j++) printf("a%d%d=%d\t", i, j, arr[i][j]); printf("\n"); } getch(); return(0); } ♣ Output :: Enter a 2x5 matrix in column major order: 1 2 3 4 5 6 7 8 9 0 You have entered: a00=1 a01=3 a02=5 a03=7 a04=9 a10=2 a11=4 a12=6 a13=8 a14=0 ♣ Downloads :: Download source code Download executable file

C Program To Calculate The Series 3+9+12+...+N

♣ Try it Out :: #include<stdio.h> #include<conio.h> int SeriesSum(int n) { if(n == 0) return(0); else return(n+SeriesSum(n-3)); } int main() { int num, i; printf("Enter the n\'th number (N will be a multiple of 3): "); scanf("%d", &num); printf("\nSeries: "); for(i=3; i<=num; i+=3) { printf("%d", i); (i == num) ? printf(" = %d", SeriesSum(num)) : printf(" + "); } getch(); return(0); } ♣ Output :: Enter the n'th number (N will be a multiple of 3): 27 Series: 3 + 6 + 9 + 12 + 15 + 18 + 21 + 24 + 27 = 135 ♣ Downloads :: Download source code Download executable file

C Program To Print 1 to N in Ascending Order Using Recursion

♣ Try it Out :: #include<stdio.h> #include<conio.h> AscendingOrder(int n) { if(n == 0) return; AscendingOrder(n-1); printf("%d ", n); } main() { int N; printf("Enter the n'th number: "); scanf("%d", &N); printf("Numbers from 1 to %d in ascending order: \n", N); AscendingOrder(N); getch(); return(0); } ♣ Output :: Enter the n'th number: 15 Numbers from 1 to 15 in ascending order: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ♣ Downloads :: Download source code Download executable file

C Program To Print 1 to N in Descending Order Using Recursion

♣ Try it Out :: #include<stdio.h> #include<conio.h> DescendingOrder(int n) { if(n == 0) return; printf("%d ", n); DescendingOrder(n-1); } main() { int N; printf("Enter the n'th number: "); scanf("%d", &N); printf("Numbers from 1 to %d in descending order: \n", N); DescendingOrder(N); getch(); return(0); } ♣ Output :: Enter the n'th number: 15 Numbers from 1 to 15 in descending order: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ♣ Downloads :: Download source code Download executable file

C Program To Reverse A Given String

♣ Try it Out :: #include<stdio.h> #include<conio.h> #define MAX 101 StringReverse(char *str) { int len = strlen(str), i; for(i=len-1; i>=0; i--) printf("%c", str[i]); printf("%c", str[i]='\0'); return; } main() { char str[MAX]; printf("Please enter a string: \n"); gets(str); printf("\nThe reverse string is: \n"); StringReverse(str); getch(); return(0); } ♣ Output :: Please enter a string: Nurul Amin Muhit The reverse string is: tihuM nimA luruN ♣ Downloads :: Download source code Download executable file

C Program To Find The Value Of One Number Raised To The Power Of Another

♣ Try it Out :: #include<stdio.h> #include<conio.h> int Power(int b, int p) { if(p == 0) return(1); else return((Power(b, p-1))*b); } int main() { int BaseNumber, PowerNumber; printf("Enter the base number: "); scanf("%d", &BaseNumber); printf("Enter the power: "); scanf("%d", &PowerNumber); printf("\nResult:\t%d ^ %d = ", BaseNumber, PowerNumber); printf("%d", Power(BaseNumber, PowerNumber)); getch(); return(0); } ♣ Output :: Enter the base number: 25 Enter the power: 3 Result: 25 ^ 3 = 15625 ♣ Downloads :: Download source code Download executable file

C Program To Print The ID And Name Of Each Student Using Struct #1

♣ Try it Out :: #include<stdio.h> #include<conio.h> struct student { int id; char name[25]; }; int main() { struct student x; printf("Enter id & name for one student: \n"); scanf("%d", &x.id); scanf("%s", x.name); printf("\nStudent id\t: %d \n", x.id); printf("Student name\t: %s \n", x.name); getch(); return(0); } ♣ Output :: Enter id & name for one student: 1002020001 Muhit Student id : 1002020001 Student name : Muhit ♣ Downloads :: Download source code Download executable file

C Program To Print The ID And Name Of Each Student Using Struct #2

♣ Try it Out :: #include<stdio.h> #include<conio.h> struct student { int id; char name[25]; }; int main() { struct student x; printf("Enter id & name for one student: \n"); scanf("%d", &x.id); scanf("%s", x.name); struct student *px; px = &x; printf("\nStudent id\t: %d \n", (*px).id); printf("Student name\t: %s \n", (*px).name); getch(); return(0); } ♣ Output :: Enter id & name for one student: 1002020001 M.A.Muhit Student id : 1002020001 Student name : M.A.Muhit ♣ Downloads :: Download source code Download executable file

C Program To Print The ID And Name Of Each Student Using Struct #3

♣ Try it Out :: #include<stdio.h> #include<conio.h> struct student { int id; char name[25]; }; main() { int TS, i; printf("Enter total number of students: "); scanf("%d", &TS); struct student s[TS]; printf("Enter id & name of %d students: \n", TS); for(i=0; i<TS; i++) { scanf("%d", &s[i].id); gets(s[i].name); } for(i=0; i<TS; i++) { printf("\nStudent id\t: %d\n", s[i].id); printf("Student name\t:%s\n\n", s[i].name); } getch(); return(0); } ♣ Output :: Enter total number of students: 3 Enter id & name of 3 students: 1002020001 Nurul Amin Muhit 1002020002 Raju Ahmed Bappa 1002020008 Foyjul Karim Moslu Student id : 1002020001 Student name : Nurul Amin Muhit Student id : 1002020002 Student name : Raju Ahmed Bappa Student id : 1002020008 Student name : Foyjul Karim Mo

C Program To Print The ID, Name & Marks Of Each Student Using Struct

♣ Try it Out :: #include<stdio.h> #include<conio.h> struct student { int id; char name[32]; int m1, m2, m3; }; int main() { struct student s[100]; int i, TS; printf("Homw many students? "); scanf("%d", &TS); printf("Enter id, name & 3 marks of %d students: \n", TS); for(i=0; i<TS; i++) { scanf("%d", &s[i].id); scanf("%s", s[i].name); scanf("%d%d%d", &s[i].m1, &s[i].m2, &s[i].m3); } for(i=0; i<TS; i++) { int TotalMarks = s[i].m1 + s[i].m2 + s[i].m3; printf("\nStudent id\t: %d \n", s[i].id); printf("Student name\t: %s \n", s[i].name); printf("Total marks\t: %d \n\n", TotalMarks); } getch(); return(0); } ♣ Output :: Homw many students? 3 Enter id, name & 3 marks of 3 students: 1002020001 Muhit 80 85 90 1002020002 Raju 85 83 91 1