Академический Документы
Профессиональный Документы
Культура Документы
Edusahayi.com
C Sahayi
C Programming Examples
First Edition
From Edusahayi.com
2|C Sahayi : Basics First Edition
C Programming Examples
Edusahayi.com
First Edition
C Programming Examples
Edusahayi.com
Preface
After joining engineering degree C programming is the one of the subject people feel very tough. But it is very important to make friendship with C since it is an essential requirement for placement. Most of the students suffer in their practical examinations and interviews due to lack of practice in programming with right logic. Edusahayi is trying to help students with C Sahayi a free ebook which contain solved C Programming questions. We divided the entire C Programming topics to three ebooks. In this first book C Sahayi Part One: Basics you will find basic problems including control staments like ifelse,nested if,switch,etc and loops including for,while,dowhile and nested loops. Please enjoy the book. We tried to include most of the programs. If you find any difficulty in understanding them please post your doubts in discussion board of www.edusahayi.com or in our facebook page www.facebook.com/edusahayi so that others also can see the discussion. If you dont want your question go public you can mail your doubts to edusahayi@gmail.com. If you want any new programs solved or any other suggestion please let us know through the resources specified above. Edusahayi
First Edition
C Programming Examples
Edusahayi.com
First Edition
C Programming Examples
Edusahayi.com
Table of Contents
Table of Contents............................................................................................................ 6 Km to feet, inch, cm conversion ..................................................................................... 7 Check for vowel .............................................................................................................. 9 Leap Year ...................................................................................................................... 10 Largest of 3 numbers .................................................................................................... 12 Arithmetic Calculator .................................................................................................... 13 Multiplication Table ...................................................................................................... 15 Prime Number .............................................................................................................. 16 Sum of Digits of a number Using while ..................................................................... 17 Sum of terms of an Arithmetic Series........................................................................... 18 Reverse of a Number Using While ............................................................................. 19 Factorial of a Number ................................................................................................... 20 Amstrong Number ........................................................................................................ 21 Nth Power of a number ................................................................................................. 23 Palindrome Number ..................................................................................................... 24 Star Patterns ................................................................................................................. 26 LCM of given numbers .................................................................................................. 34 Decimal to Binary Conversion ...................................................................................... 36 Generation of Fibonacci Series ..................................................................................... 37
First Edition
C Programming Examples
Edusahayi.com
First Edition
C Programming Examples
Edusahayi.com
First Edition
C Programming Examples
Edusahayi.com
First Edition
C Programming Examples
Edusahayi.com
Leap Year
Q : C program to check whether entered year is leap year or not. Leap Year Algorithm : if year is divisible by 400 then is_leap_year else if year is divisible by 100 then not_leap_year else if year is divisible by 4 then is_leap_year else not_leap_year Program #include<stdio.h> #include<conio.h> main() { int y; clrscr(); printf("\n enter the year\n ");
C Programming Examples
Edusahayi.com
printf(" common year"); if(y%1000==0) { if(y%4000==0) printf(" common year"); } } } else printf(" leap year"); } else printf(" common year"); getch(); }
11 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Largest of 3 numbers
Q: C Code to find Largest of 3 given numbers Nested if else #include<stdio.h> #include<conio.h> main() { int a,b,c; clrscr(); printf(Enter the nos :); scanf(%d%d%d,&a,&b,&c); if(a>b) { if(a>c) printf(%d is largest,a); else printf(%d is largest,c); } else { if(b>c) printf(%d is largest,b); else printf(%d is largest,c); } getch(); } 12 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
Arithmetic Calculator
Q : An arithmetic calculator to do basic arithmetic operations on two numbers. Select operations (Addition, subtraction, multipkication and division) from a menu.
#include<stdio.h> #include<conio.h> main() { float a,b,,r; int c; clrscr(); printf("\n enter the two No.s:"); scanf("%f%f",&a,&b); printf("\n CODES \n 1.addition\n 2.substraction\n 3.multiplication\n 4.division\n enter the function"); scanf("%d",&c); switch(c) { case 1: r=a+b; break; 13 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
case 2: r=a-b; break; case 3: r=a*b; break; case 4: r=a/b; break; default: printf("\n invalid code"); break; } printf("\n%f",&r); getch(); }
14 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Multiplication Table
Q: Programme to print multiplication table of a give number
#include<stdio.h> #include<conio.h> main() { clrscr(); int i,j,k; clrscr(); printf("\n **MULTIPLICATION TABLE**\n\n\n ENTER THE NO:");
15 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Prime Number
Q: To check whether entered number is prime or not #include<stdio.h> #include<conio.h> main() { int i,j,k; clrscr(); printf("enter the no:"); scanf("%d",&i); for(j=2;i%j!=0;j++) {} if(j==i) printf("\nprime no."); else printf("\nnot prime no"); getch(); }
16 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
17 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
18 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
19 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Factorial of a Number
#include<stdio.h> #include<conio.h> main() { float i=1,j=1,l; clrscr(); printf("\nEnter the No.:"); scanf("%f",&l); while(i<=l) { j=j*i; i=i++; } printf("\nfactoril is %.0f",j); getch(); }
20 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Amstrong Number
Amstrong Number : If sum of cubes of digits of a number is equal to the number then it is called amstrong number
#include<stdio.h> #include<conio.h> main() { int i,j,a,k=0; clrscr(); printf("\n enter the no:"); scanf("%d",&i); a=i; while(i!=0) { j=i%10; k=k+(j*j*j); i=i/10; } if(k==a) printf("amstrong no"); else 21 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
22 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
23 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Palindrome Number
Palindrom : If a number and its reverse are the same then it is a Palindrom Eg:121 Program #include<stdio.h> #include<conio.h> main() { int a,i,b,r=0; clrscr(); printf("Enter the no : "); scanf("%d",&a); b=a; while(a!=0) { r=r*10+a%10; a=a/10; } if(r==b) printf("Palindrom"); else 24 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
25 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Star Patterns
Q : Code to print following patters for specified number of rows 1 * ** *** **** 2 **** *** ** * 3 * ** *** **** *** ** * 4 * ** *** ****
26 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
5 **** *** ** * 6 * ** *** **** *** ** * Program #include<stdio.h> #include<conio.h> main() { int m,i,j,r,k,ch; char x; clrscr(); do { clrscr();
27 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
printf("\n
1.RIGHT TRIANGLE-up\n 2.RIGHT TRIANGLE-down\n 3.TRIANGLE-common\n 4.EQUILATERAL TRIANGLE-up\n 5.EQUILATERAL TRIANGLE-down\n 6.DIAMOND\n\n "); printf("ENTER NO. OF ROWS:"); scanf("%d",&r); printf("\n ENTER THE PATTERN:"); scanf("%d",&ch); clrscr(); printf("\n\n"); //1 if(ch==1) { for(i=1;i<=r;i++) { for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } } //2 28 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
else if(ch==2) { for(i=r;i>=0;i--) { for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } } //3 else if(ch==3) { for(i=1;i<=r;i++) { for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } 29 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
for(i=r-1;i>=0;i--) { for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } } //4 else if(ch==4) { for(i=1;i<=r;i++) { m=r-i; for(k=0;k<m;k++) printf(" "); for(j=0;j<i;j++) { printf(" *"); } printf("\n"); 30 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
} } //5 else if(ch==5) { for(i=r;i>=0;i--) { m=r-i; for(k=0;k<m;k++) printf(" "); for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } } //6 else if(ch==6) { for(i=1;i<=r;i++) { 31 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
m=r-i; for(k=0;k<m;k++) printf(" "); for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } for(i=r-1;i>=0;i--) { m=(r)-i; for(k=0;k<m;k++) printf(" "); for(j=0;j<i;j++) { printf(" *"); } printf("\n"); } } else 32 | C S a h a y i : B a s i c s First Edition
C Programming Examples
Edusahayi.com
33 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
34 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
break(); } } getch(); }
35 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
36 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
37 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Coming Soon
38 | C S a h a y i : B a s i c s
First Edition
C Programming Examples
Edusahayi.com
Coming Soon
39 | C S a h a y i : B a s i c s
First Edition