Language: - Itis the media of communication. Cis the Languageof programs & functions developed by Dennis Ritchie in 1972- 73 & in AT & T Bell Laboratories in USA. Programs: - Itis a group of statement which are executed step by step to performa desire task. Programs arethe instructions given to the system. Instruction: - A single order given to the systemis called Instruction. Software: - Itis a group of programs working with coordination with each other to get the desired result. Software is of two types: - 1. SystemSoftware: - like operating system(window) 2. ApplicationSoftware: - like MS Office, Adobe Reader and Anti-Virus. Language is of two types: - 1. Low Level Language: - Which is also called Machine language. E.g.: - C,C++ 2. High Level Language: - Which is used in simple English Language. E.g.: - HTML, PHP, Java and DotNet. C is also called Middle Level Language becauseit is flexible & compatible with machine as like Low Level Languageor use friendly as like high level language. Translators: - These are the software’s which converthigh level language or vice versa. There are 2 types of Translators. 1. Compiler
2. Interpreter Structure of C Language 1. Write a program toget the output the output Hello? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c; printf (“Enter the value of a & b”); scanf (“%d%d”,&a,&b); c=a+b; printf (“n Sumis of %d”,c); getch (); } Output: Hello 2. Write a program toget the sum of a & b? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c; printf (“Enter the value of a & b”); scanf (“%d%d”,&a,&b); C=a+b; printf (“n Sum is of %d”, c); getch (); }
Output: Enter the value of a & b:- A=3 B=2 Output will be 5. 3. Write a program to enter 3 numbers & calculate their sum? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c, d; clrscr (); printf (“Enter the value of a & b & c”); scanf (“%d%d%d”,&a,&b,&c); d=a+b+c; printf (“n Sum is of %d”, d); getch (); } Output: Enter the value of a,b,c:- A=3 B=4 C=5 The sum is 12 4.W.A.P to calculate Simple Interest? # include <stdio.h> # include <conio.h> void main () { Intp, r, t, s; clrscr (); printf (“Enter the value of p & r & t”); scanf (“%d%d%d”, &p, &r, &t); S=p*r*t/100;
printf (“n Simple Interestis of %d”, s); getch (); } Output:put value of p=1000, r=2, t=1 Simple interest is =20 5.W.A.P to calculate the perimeter of circle &rectangle? # include <stdio.h> # include <conio.h> void main () { int a, l, b, r; clrscr (); printf (“Enter the value of l & b & r”); scanf (“%d%d%d”, &l, &b, &r); A=2*a+b; B=2*3.14*r; printf (“n Perimeter of rect. & circle is of %dn%d”, a, b); getch (); } Output:put l=6,b=8,r=4 Answer is = 20,25 6.W.A.P to enter basic salary, da, hpa, pf & calculate total salary & net salary? # include <stdio.h> # include <conio.h> Void main () { Int ts, ns, bs, da, hpa, pf; Clrscr (); Printf (“Enter the value of bs & da & hpa & pf”); Scanf (“%d%d%d%d”, &bs, &da, &hpa, &pf); Ts=bs+hpa+da; Ns=ts-pf; Printf (“n TS & NS is of %dn%d”, ts, ns) Getch (); } Output: put bs=67, da=67, hpa=56, pf=87; Answer is = Ts=190, Ns=103
7.W.A.P to enter initial reading, Final reading &charges per unit (CPU) & calculate units consume & bill? # include <stdio.h> # include <conio.h> void main () { int uc, b, ir, fr, cpu; clrscr (); printf (“Enter the value of ir & cpu & fr”); scanf (“%d%d%d”, &ir, &cpu, &fr); uc =fr-ir; b =uc*cpu; printf (“n UC & B is of %dn%d”, uc, b); getch (); } Output= put ir=60, cpu=5, fr=80 Answer: - Uc= 20; B=100 8.W.A.P to get the maximum number? # include <stdio.h> # include <conio.h> void main () { int a, b, max; printf (“n Enter the value a & b”); scanf (“%d%d”, &a, &b); max= (a>b)? a:b; printf (“n Max No. is %d”, max); getch (); } Output: put a=9, b=6 Answer is: - Max No. is 9 9.W.A.P to enter any no. & click whether it is evenor odd? # include <stdio.h> # include <conio.h>
void main () { int num; clrscr (); printf (“Enter the value of num”); scanf (“%d”, & num); (num%2==0)? Printf (“even”): printf (“odd”); printf (“n number is %d”, num); getch (); } Output: Enter the value of num=8 Even 8 10. W.A.P to enter a number and check whether it is positive or negative? # include <stdio.h> # include <conio.h> Void main () { Int num; Printf (“Enter the value of num”); Scanf (“%d”, &num); (num>0)? Printf (“positive”): printf (“negative”); Getch (); } Output: Enter the value of num: 7 positive 11. W.A.P to enter any year whether it is leap year or not? # include <stdio.h> # include <conio.h> void main () {
int num; printf (“Enter the value of num”); scanf (“%d”, &num); (num%4==0)? Printf (“leap year”): printf (“not leap year”); printf (“n leap year is %d”, num); getch (); } Output: Enter the value of num: 2013 Not a leap year. 12. W.A.P to enter cost prize & selling prize & check whether there is profit or loss? # include <stdio.h> # include <conio.h> void main () { int cp, sp; clrscr (); printf (“Enter the value of cp & sp”); scanf (“%d%d”, &cp, &sp); (cp<sp)? Printf (“profit”): printf (“loss”); getch (); } Output: Enter the value of cp & sp: 500,300 loss of 200 13. W.A.P to input any age & check whether the person can vote or not? # include <stdio.h> # include <conio.h> Void main () { Int age; Printf (“Enter the value of age”);
Scanf (“%d”, &age); (age<18==0)? Printf (“can vote”): printf (“can’t Vote”); Getch (); } Output: Enter the value of age: 18 Can Vote. If Else Programs 14. W.A.P to enter the loss & profit? # include <stdio.h> # include <conio.h> void main () { int cp, sp, l, p; clrscr (); printf (“Enter the value of cp & sp”); scanf (“%d%d”, &cp, &sp); if (cp>sp) { l=cp-sp; printf (“n loss is of %d”, l); } else { p=sp-cp; printf (“n profit is of %d”, p); } getch (); } Output: cp=500, sp=400 Loss=100
15. W.A.P to enter the Positive or Negative? # include <stdio.h> # include <conio.h> void main () { int num; clrscr (); printf (“Enter the value of num”); scanf (“%d”, &num); if (num>0) { printf (“n Number is Positive”); } else { printf (“n Number is Negative”); } getch (); } Output: Enter the value of num 7 7 is positive 16. W.A.P to enter the age and to know the person can vote or not? # include <stdio.h> # include <conio.h> void main () { int age; clrscr (); printf (“Enter the value of age”);
scanf (“%d”, &age); if (age>18) { printf (“n can Vote”); } else { printf (“n can’t Vote”); } getch (); } Output: Enter the value of age: - 18 Can Vote 17. W.A.P to enter the value of a number whether it is odd or even? # include <stdio.h> # include <conio.h> Void main () { Int num; Clrscr (); Printf (“Enter the value of num”); Scanf (“%d”, &num); If (num%2==0) { Printf (“n Number is even”); } Else { Printf (“n Number is odd”); } Getch (); }
Output: Enter the value of num 2 Even 18. W.A.P to enter the value of Maximum number? # include <stdio.h> # include <conio.h> void main () { int a, b, max; clrscr (); printf (“Enter the value of a & b”); scanf (“%d%d”, &a, &b); if (a>b) { printf (“n a is max is %d”, a); } else { printf (“n b is max is %d”, b); } getch (); } Output: Enter the value of a=45,b=67 B is max is 67 19. W.A.P to enter any alphabet to check vowel or consonant? # include <stdio.h> # include <conio.h> void main () {
char alpha; printf (“enter any alphabet”); scanf (“%c”, &alphabet”); if (alpha==’a’||alpha==’e’||alpha==’i’||alpha==’o’||alpha==’u’) printf (“vowel”); else printf (“Consonant”); getch (); } Output: Enter any alphabet R= Consonant 20. W.A.P to enter any age? # include <stdio.h> # include <conio.h> void main () { int age; clrscr (); printf (“enter any age”); scanf (“%d”, &age); if (age>1 && age<12) printf (“child”); else if (age>13 && age<50) printf (“mature”); else printf (“old”); getch (); } Output: Enter any age=56 Old
21. W.A.P to enter any Month & check the season? # include <stdio.h> # include <conio.h> Void main () { Int m; Clrscr (); Printf (“Enter any month”); Scanf (“%d”, &m); If (m==12||m==1||m==2) Printf (“winter”); Else if (m==3||m==4||m==5) Printf (“spring”); Else if (m==6||m==7||m==8) Printf (“summer”); Else Printf (“autumn”); Getch (); } Output: Enter any month= 4 Spring 22. W.A.P to enter the marks of 5 subjects & calculate its percentage & check position? # include <stdio.h> # include <conio.h> void main () { int m1, m2, m3, m4, m5, p; clrscr (); printf (“enter the value of m1 & m2 & m3 & m4 & m5”);
scanf (“%d%d%d%d%d”, &m1, &m2, &m3, &m4, &m5); p= (m1+m2+m3+m4+m5)/5; if (p>80) printf (“distinction”); else if (p>70 && p<80) printf (“1st position”); else if (p>60 && p<70) printf (“2nd position”); else if (p>30 && p<60) printf (“3rd position”); else printf (“fail”); getch (); } Output: Enter the value of m1=1, m2=2, m3=3, m4=4, m5=5 Fail 23. W.A.P to calculate max out of 3 numbers? # include <stdio.h> # include <conio.h> void main () { int a, b, c; printf (“enter 3 nos.”); scanf (“%d%d%d”, &a, &b, &c); if (a>b) { if (a>c) printf (“a is max”); else printf (“c is max”); }
else { if (b>c) printf (“b is max”); else printf (“c is max”); } else [ if (b>c) printf (“b is max”); else printf (“c is max”); } getch (); } Output: Enter any 3 nos. 12, 16, 72 C is max. Programs of Switch Control Constructs It is an alternative to if else construct 24. W.A.P to enter color? # include <stdio.h> # include <conio.h> Void main () { Char ch; Printf (“Color Menu”);
Printf (“n R for Red”); Printf (“n B for Blue”); Printf (“n G for Green”); Printf (“n Enter your choice”); Scanf (“%c”, &ch); Switch (ch) { Case ‘R’: printf (“Roses are Red”); Break; Case ‘B’: printf (“Sky is blue”); Break; Case ‘G’: printf (“Grass is Green”); Break; Default: printf (“wrong choice”); } Getch (); } Output: Enter your choice: R Roses are Red 25. W.A.P to enter the areaof rect. & circle? # include <stdio.h> # include <conio.h> Void main () { Intch, l, b, r, a, p; Clrscr (); Printf (“Enter the value of l & b & r); Scanf (“%d%d%d”, &l, &b, &r); Switch (ch) { Case 1: a=l*b; Printf (“n Area is %d”, a); Break;
Case 2: p=3.14*r*r; Printf (“n Area of circle is %d”, p); Break; Default: printf (“Wrong Choice”); } Getch (); } Output: Enter the value of l=6, b=7, r=8 Enter your choice 1 Answer: 42 26. W.A.P to enter the Addition, Subtraction, Division, Multiplication? # include <stdio.h> # include <conio.h> void main () { char ch; int a, b, c; clrscr (); printf (“enter your choice”); scanf (“%c”, &ch); printf (“enter the value of a & b”); scanf (“%d%d”, &a, &b); switch (ch) { case ‘+’: c=a+b; printf (“n addition is %d”, c); break; case ‘-‘: c=a-b; printf (“n subtraction is %d”, c); break; case ‘*’: c=a*b; printf (“n multiplication is %d”, c); break; case ‘/’: c=a/b; printf (“n division is %d”, c); break;
default: printf (“wrong choice”); } getch (); } Output: Enter your choice 1 Enter the value of a=5,b=6 Addition is 11. 27. W.A.P to check whether the enteredalphabet is avowel or consonant? # include <stdio.h> # include <conio.h> Void main () { Char ch; Clrscr (); Printf (“Enter your choice”); Scanf (“%c”, &ch); Switch (ch) { Case ‘a: Case ‘e’: Case ‘I’: Case ’o’: Case ‘u’: Printf (“Vowel”); Break; Default: printf (“Consonant”): } Getch (); } Output: Enter your choice: b
Consonant 28. W.A.P to enter the month & Season with switch? # include <stdio.h> # include <conio.h> Void main () { int m; Clrscr (); Printf (“Enter your choice”); Scanf (“%d”, &m); Switch (m) { Case 12: Case 1: Case 2: Printf (“Winter”); Break; Case 3: Case 4: Case 5: Printf (“Spring”); Break; Case 6: Case 7: Case 8: Printf (“Summer”); Break; Default: printf (“Autumn”);
} Getch (); } Output: Enter your choice 12 Winter Control Structures or Control Constructs They are those constructs which control the flow of execution of the program. It is of 3 types: - (i). For loop (ii). While loop (iii). Do While loop 29. W.A.P to find the sum of first five natural numbers? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the natural nos. are”); for (i=1; i<=5; i++)
{ printf (“%d”, i); } getch (); } Output: The Natural Nos. are 1 2 3 4 5. 30. W.A.P to print first 10 evennumbers? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the even nos. are”); for (i=2; i<=20; i+=2) { printf (“%d”, i); } getch (); } Output: The Natural numbers are 2,4,6,8,10,12,14,16,18,20 31. W.A.P to find the sum of first five natural numbers? # include <stdio.h> # include <conio.h> void main () { int i, sum=0; clrscr ();
printf (“the sums of firstfive natural nos. are”); for (i=1; i<5; i++) { sum= sum+i; } printf (“%d”, sum); getch (); } Output: The sum of first five Natural nos. are =15. 32. W.A.P to print first 100 oddnos.? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the odd nos. are”); for (i=1; i<=19; i+=2) { printf (“%d”, i); } getch (); } Output: The first 10 odd nos. are =1, 3, 5, 7, 9, 11, 13, 15, 17, 19. Programs of For Loop (Fibonacci Series)
33. W.A.P to enter the value of a & b? # include <stdio.h> # include <conio.h> void main () { int a=0, b=1, c, i; for (i=1; i<=10; i++) { printf (“%d”, a); c=a+b; a=b; b=c; } getch (); } Output: 112358132134 34. W.A.P to find sum of n Numbers? # include <stdio.h> # include <conio.h> void main () { int a, i, sum=0; clrscr (); printf (“enter the value of n”); scanf (“%d”, &n); for (i=1; i<=n; i++) { sum=sum+i; }
printf (“%d”, sum); getch (); } Output: Enter the value of n=4 Answer: 10 35. W.A.P to get factorial of no.? # include <stdio.h> # include <conio.h> void main () { int num, fact=0, i; printf (“enter any no.”); scanf (“%d”, &num); for (i=num; i>=1; i--) { fact =fact*i; } printf (“factorialof a no. is %d”, fact); getch (); } Output: Enter any no. =4 Fact. Of a no is 0. 36. W.A.P to make a table of any no.? # include <stdio.h> # include <conio.h> void main () { int num, i, product;
clrscr (); printf (“enter the value of num”); scanf (“%d”, &num); for (i=1; i<=10; i++) { product= num*i; printf (“n %d*%d=%d”, num, i, prod.); } getch (); } Output: Enter the value of num 2 2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 2*10=20 37. W.A.P to find the power of the number? # include <stdio.h> # include <conio.h> Void main () { Inty, x, prod=1, I; clrscr (); printf (“Enter the value of x & y’);
scanf (“%d%d”, &x, &y); for (i=1; i<=y; i++) { prod =prod*x; } printf (“%d”, prod); getch (); } Output: Enter the value of x=5, y=2: - 25 38. W.A.P to find the sum of square of a number? # include <stdio.h> # include <conio.h> Void main () { Inty, I, prod, sum=0; Clrscr (); For (i=1; i<=5; i++) { Prod =i*i; Sum =sum+ prod; } Printf (“%d”, sum); Getch (); } Output: 55. 39. W.A.P to find sum and average of n numbers? # include <stdio.h> # include <conio.h> Void main () { int n, i, num=0, average;
clrscr (); printf (“Enter the value of n”); scanf (“%d”, &n); for (i=1; i<=n; i++) { num = num + I; } printf (“Sumis %d”, num); average= num/n; printf (“n Average is %d”, average); getch (); } Output: Enter the value of n = 40 Sum is 820 Average is 20. 40. W.A.P to find reverses of a number? # include <stdio.h> # include <conio.h> void main () { int n, r=0; printf (“enter any no.”); scanf (“%d”, &n); while (n! =0) { r=r*10; r=r+n%10; n=n/10; } printf (“reverseof a no. is %d”, r);
getch (); } Output: Enter any no. 123 Reverse of a no. is 321. 41. W.A.P to find palindrome of a no.? # include <stdio.h> # include <conio.h> Void main () { Intn, r=0, temp; Printf (“Enter any number”); Scanf (“%d”, &n); Temp=n; While (temp! =0) { R=r*10; R=r+temp%10 Temp=temp/10; } If (n==r) Printf (“No. is palindrome”); Else Printf (“No. is not palindrome”); Getch (); } Output: Enter any number 121 No. is palindrome Or Enter any number 122 No. is not palindrome
Difference b/w While Loop & Do While Loop While Loop Do While Loop Condition is check first and then control goes into the loop. Condition is checked but one time loop gets executed. It is called entry control loops. It is called exit control loops. 42. Draw the Pattern: - 11111 22222 33333 44444 55555 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=1; i<=5; i++) { Printf (“n”); For (j=1; j<=5; j++) { Printf (“%d”, i); } }
Getch (); } Output: 11111 22222 33333 44444 55555 43. Draw a pattern: - 1 22 333 4444 55555 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=1; i<=5; i++) { Printf (“n”); For (j=1; j<=1; j++) { Printf (“%d”, i); } } Getch ();
} Output: 1 22 333 4444 55555 44. Draw the pattern: - 55555 4444 333 22 1 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=5; i>=1; i--) { Printf (“n”); For (j=1; j<=I; j++) { Printf (“%d”, i); } } Getch (); }
Output: 55555 4444 333 22 1 45. Draw the pattern: - 12345 1234 123 12 1 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=5; i>=1; i--) { Printf (“n”); For (j=1; j<=I; j++) { Printf (“%d”, j); } } Getch (); }
Output: 12345 1234 123 12 1

Best C Programming Solution

  • 1.
    Language: - Itisthe media of communication. Cis the Languageof programs & functions developed by Dennis Ritchie in 1972- 73 & in AT & T Bell Laboratories in USA. Programs: - Itis a group of statement which are executed step by step to performa desire task. Programs arethe instructions given to the system. Instruction: - A single order given to the systemis called Instruction. Software: - Itis a group of programs working with coordination with each other to get the desired result. Software is of two types: - 1. SystemSoftware: - like operating system(window) 2. ApplicationSoftware: - like MS Office, Adobe Reader and Anti-Virus. Language is of two types: - 1. Low Level Language: - Which is also called Machine language. E.g.: - C,C++ 2. High Level Language: - Which is used in simple English Language. E.g.: - HTML, PHP, Java and DotNet. C is also called Middle Level Language becauseit is flexible & compatible with machine as like Low Level Languageor use friendly as like high level language. Translators: - These are the software’s which converthigh level language or vice versa. There are 2 types of Translators. 1. Compiler
  • 2.
    2. Interpreter Structure ofC Language 1. Write a program toget the output the output Hello? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c; printf (“Enter the value of a & b”); scanf (“%d%d”,&a,&b); c=a+b; printf (“n Sumis of %d”,c); getch (); } Output: Hello 2. Write a program toget the sum of a & b? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c; printf (“Enter the value of a & b”); scanf (“%d%d”,&a,&b); C=a+b; printf (“n Sum is of %d”, c); getch (); }
  • 3.
    Output: Enter thevalue of a & b:- A=3 B=2 Output will be 5. 3. Write a program to enter 3 numbers & calculate their sum? # include <stdio.h> # include <conio.h> Void main () { Inta, b, c, d; clrscr (); printf (“Enter the value of a & b & c”); scanf (“%d%d%d”,&a,&b,&c); d=a+b+c; printf (“n Sum is of %d”, d); getch (); } Output: Enter the value of a,b,c:- A=3 B=4 C=5 The sum is 12 4.W.A.P to calculate Simple Interest? # include <stdio.h> # include <conio.h> void main () { Intp, r, t, s; clrscr (); printf (“Enter the value of p & r & t”); scanf (“%d%d%d”, &p, &r, &t); S=p*r*t/100;
  • 4.
    printf (“n SimpleInterestis of %d”, s); getch (); } Output:put value of p=1000, r=2, t=1 Simple interest is =20 5.W.A.P to calculate the perimeter of circle &rectangle? # include <stdio.h> # include <conio.h> void main () { int a, l, b, r; clrscr (); printf (“Enter the value of l & b & r”); scanf (“%d%d%d”, &l, &b, &r); A=2*a+b; B=2*3.14*r; printf (“n Perimeter of rect. & circle is of %dn%d”, a, b); getch (); } Output:put l=6,b=8,r=4 Answer is = 20,25 6.W.A.P to enter basic salary, da, hpa, pf & calculate total salary & net salary? # include <stdio.h> # include <conio.h> Void main () { Int ts, ns, bs, da, hpa, pf; Clrscr (); Printf (“Enter the value of bs & da & hpa & pf”); Scanf (“%d%d%d%d”, &bs, &da, &hpa, &pf); Ts=bs+hpa+da; Ns=ts-pf; Printf (“n TS & NS is of %dn%d”, ts, ns) Getch (); } Output: put bs=67, da=67, hpa=56, pf=87; Answer is = Ts=190, Ns=103
  • 5.
    7.W.A.P to enterinitial reading, Final reading &charges per unit (CPU) & calculate units consume & bill? # include <stdio.h> # include <conio.h> void main () { int uc, b, ir, fr, cpu; clrscr (); printf (“Enter the value of ir & cpu & fr”); scanf (“%d%d%d”, &ir, &cpu, &fr); uc =fr-ir; b =uc*cpu; printf (“n UC & B is of %dn%d”, uc, b); getch (); } Output= put ir=60, cpu=5, fr=80 Answer: - Uc= 20; B=100 8.W.A.P to get the maximum number? # include <stdio.h> # include <conio.h> void main () { int a, b, max; printf (“n Enter the value a & b”); scanf (“%d%d”, &a, &b); max= (a>b)? a:b; printf (“n Max No. is %d”, max); getch (); } Output: put a=9, b=6 Answer is: - Max No. is 9 9.W.A.P to enter any no. & click whether it is evenor odd? # include <stdio.h> # include <conio.h>
  • 6.
    void main () { intnum; clrscr (); printf (“Enter the value of num”); scanf (“%d”, & num); (num%2==0)? Printf (“even”): printf (“odd”); printf (“n number is %d”, num); getch (); } Output: Enter the value of num=8 Even 8 10. W.A.P to enter a number and check whether it is positive or negative? # include <stdio.h> # include <conio.h> Void main () { Int num; Printf (“Enter the value of num”); Scanf (“%d”, &num); (num>0)? Printf (“positive”): printf (“negative”); Getch (); } Output: Enter the value of num: 7 positive 11. W.A.P to enter any year whether it is leap year or not? # include <stdio.h> # include <conio.h> void main () {
  • 7.
    int num; printf (“Enterthe value of num”); scanf (“%d”, &num); (num%4==0)? Printf (“leap year”): printf (“not leap year”); printf (“n leap year is %d”, num); getch (); } Output: Enter the value of num: 2013 Not a leap year. 12. W.A.P to enter cost prize & selling prize & check whether there is profit or loss? # include <stdio.h> # include <conio.h> void main () { int cp, sp; clrscr (); printf (“Enter the value of cp & sp”); scanf (“%d%d”, &cp, &sp); (cp<sp)? Printf (“profit”): printf (“loss”); getch (); } Output: Enter the value of cp & sp: 500,300 loss of 200 13. W.A.P to input any age & check whether the person can vote or not? # include <stdio.h> # include <conio.h> Void main () { Int age; Printf (“Enter the value of age”);
  • 8.
    Scanf (“%d”, &age); (age<18==0)?Printf (“can vote”): printf (“can’t Vote”); Getch (); } Output: Enter the value of age: 18 Can Vote. If Else Programs 14. W.A.P to enter the loss & profit? # include <stdio.h> # include <conio.h> void main () { int cp, sp, l, p; clrscr (); printf (“Enter the value of cp & sp”); scanf (“%d%d”, &cp, &sp); if (cp>sp) { l=cp-sp; printf (“n loss is of %d”, l); } else { p=sp-cp; printf (“n profit is of %d”, p); } getch (); } Output: cp=500, sp=400 Loss=100
  • 9.
    15. W.A.P toenter the Positive or Negative? # include <stdio.h> # include <conio.h> void main () { int num; clrscr (); printf (“Enter the value of num”); scanf (“%d”, &num); if (num>0) { printf (“n Number is Positive”); } else { printf (“n Number is Negative”); } getch (); } Output: Enter the value of num 7 7 is positive 16. W.A.P to enter the age and to know the person can vote or not? # include <stdio.h> # include <conio.h> void main () { int age; clrscr (); printf (“Enter the value of age”);
  • 10.
    scanf (“%d”, &age); if(age>18) { printf (“n can Vote”); } else { printf (“n can’t Vote”); } getch (); } Output: Enter the value of age: - 18 Can Vote 17. W.A.P to enter the value of a number whether it is odd or even? # include <stdio.h> # include <conio.h> Void main () { Int num; Clrscr (); Printf (“Enter the value of num”); Scanf (“%d”, &num); If (num%2==0) { Printf (“n Number is even”); } Else { Printf (“n Number is odd”); } Getch (); }
  • 11.
    Output: Enter thevalue of num 2 Even 18. W.A.P to enter the value of Maximum number? # include <stdio.h> # include <conio.h> void main () { int a, b, max; clrscr (); printf (“Enter the value of a & b”); scanf (“%d%d”, &a, &b); if (a>b) { printf (“n a is max is %d”, a); } else { printf (“n b is max is %d”, b); } getch (); } Output: Enter the value of a=45,b=67 B is max is 67 19. W.A.P to enter any alphabet to check vowel or consonant? # include <stdio.h> # include <conio.h> void main () {
  • 12.
    char alpha; printf (“enterany alphabet”); scanf (“%c”, &alphabet”); if (alpha==’a’||alpha==’e’||alpha==’i’||alpha==’o’||alpha==’u’) printf (“vowel”); else printf (“Consonant”); getch (); } Output: Enter any alphabet R= Consonant 20. W.A.P to enter any age? # include <stdio.h> # include <conio.h> void main () { int age; clrscr (); printf (“enter any age”); scanf (“%d”, &age); if (age>1 && age<12) printf (“child”); else if (age>13 && age<50) printf (“mature”); else printf (“old”); getch (); } Output: Enter any age=56 Old
  • 13.
    21. W.A.P toenter any Month & check the season? # include <stdio.h> # include <conio.h> Void main () { Int m; Clrscr (); Printf (“Enter any month”); Scanf (“%d”, &m); If (m==12||m==1||m==2) Printf (“winter”); Else if (m==3||m==4||m==5) Printf (“spring”); Else if (m==6||m==7||m==8) Printf (“summer”); Else Printf (“autumn”); Getch (); } Output: Enter any month= 4 Spring 22. W.A.P to enter the marks of 5 subjects & calculate its percentage & check position? # include <stdio.h> # include <conio.h> void main () { int m1, m2, m3, m4, m5, p; clrscr (); printf (“enter the value of m1 & m2 & m3 & m4 & m5”);
  • 14.
    scanf (“%d%d%d%d%d”, &m1,&m2, &m3, &m4, &m5); p= (m1+m2+m3+m4+m5)/5; if (p>80) printf (“distinction”); else if (p>70 && p<80) printf (“1st position”); else if (p>60 && p<70) printf (“2nd position”); else if (p>30 && p<60) printf (“3rd position”); else printf (“fail”); getch (); } Output: Enter the value of m1=1, m2=2, m3=3, m4=4, m5=5 Fail 23. W.A.P to calculate max out of 3 numbers? # include <stdio.h> # include <conio.h> void main () { int a, b, c; printf (“enter 3 nos.”); scanf (“%d%d%d”, &a, &b, &c); if (a>b) { if (a>c) printf (“a is max”); else printf (“c is max”); }
  • 15.
    else { if (b>c) printf (“bis max”); else printf (“c is max”); } else [ if (b>c) printf (“b is max”); else printf (“c is max”); } getch (); } Output: Enter any 3 nos. 12, 16, 72 C is max. Programs of Switch Control Constructs It is an alternative to if else construct 24. W.A.P to enter color? # include <stdio.h> # include <conio.h> Void main () { Char ch; Printf (“Color Menu”);
  • 16.
    Printf (“n Rfor Red”); Printf (“n B for Blue”); Printf (“n G for Green”); Printf (“n Enter your choice”); Scanf (“%c”, &ch); Switch (ch) { Case ‘R’: printf (“Roses are Red”); Break; Case ‘B’: printf (“Sky is blue”); Break; Case ‘G’: printf (“Grass is Green”); Break; Default: printf (“wrong choice”); } Getch (); } Output: Enter your choice: R Roses are Red 25. W.A.P to enter the areaof rect. & circle? # include <stdio.h> # include <conio.h> Void main () { Intch, l, b, r, a, p; Clrscr (); Printf (“Enter the value of l & b & r); Scanf (“%d%d%d”, &l, &b, &r); Switch (ch) { Case 1: a=l*b; Printf (“n Area is %d”, a); Break;
  • 17.
    Case 2: p=3.14*r*r; Printf(“n Area of circle is %d”, p); Break; Default: printf (“Wrong Choice”); } Getch (); } Output: Enter the value of l=6, b=7, r=8 Enter your choice 1 Answer: 42 26. W.A.P to enter the Addition, Subtraction, Division, Multiplication? # include <stdio.h> # include <conio.h> void main () { char ch; int a, b, c; clrscr (); printf (“enter your choice”); scanf (“%c”, &ch); printf (“enter the value of a & b”); scanf (“%d%d”, &a, &b); switch (ch) { case ‘+’: c=a+b; printf (“n addition is %d”, c); break; case ‘-‘: c=a-b; printf (“n subtraction is %d”, c); break; case ‘*’: c=a*b; printf (“n multiplication is %d”, c); break; case ‘/’: c=a/b; printf (“n division is %d”, c); break;
  • 18.
    default: printf (“wrongchoice”); } getch (); } Output: Enter your choice 1 Enter the value of a=5,b=6 Addition is 11. 27. W.A.P to check whether the enteredalphabet is avowel or consonant? # include <stdio.h> # include <conio.h> Void main () { Char ch; Clrscr (); Printf (“Enter your choice”); Scanf (“%c”, &ch); Switch (ch) { Case ‘a: Case ‘e’: Case ‘I’: Case ’o’: Case ‘u’: Printf (“Vowel”); Break; Default: printf (“Consonant”): } Getch (); } Output: Enter your choice: b
  • 19.
    Consonant 28. W.A.P toenter the month & Season with switch? # include <stdio.h> # include <conio.h> Void main () { int m; Clrscr (); Printf (“Enter your choice”); Scanf (“%d”, &m); Switch (m) { Case 12: Case 1: Case 2: Printf (“Winter”); Break; Case 3: Case 4: Case 5: Printf (“Spring”); Break; Case 6: Case 7: Case 8: Printf (“Summer”); Break; Default: printf (“Autumn”);
  • 20.
    } Getch (); } Output: Enteryour choice 12 Winter Control Structures or Control Constructs They are those constructs which control the flow of execution of the program. It is of 3 types: - (i). For loop (ii). While loop (iii). Do While loop 29. W.A.P to find the sum of first five natural numbers? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the natural nos. are”); for (i=1; i<=5; i++)
  • 21.
    { printf (“%d”, i); } getch(); } Output: The Natural Nos. are 1 2 3 4 5. 30. W.A.P to print first 10 evennumbers? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the even nos. are”); for (i=2; i<=20; i+=2) { printf (“%d”, i); } getch (); } Output: The Natural numbers are 2,4,6,8,10,12,14,16,18,20 31. W.A.P to find the sum of first five natural numbers? # include <stdio.h> # include <conio.h> void main () { int i, sum=0; clrscr ();
  • 22.
    printf (“the sumsof firstfive natural nos. are”); for (i=1; i<5; i++) { sum= sum+i; } printf (“%d”, sum); getch (); } Output: The sum of first five Natural nos. are =15. 32. W.A.P to print first 100 oddnos.? # include <stdio.h> # include <conio.h> void main () { int i; clrscr (); printf (“the odd nos. are”); for (i=1; i<=19; i+=2) { printf (“%d”, i); } getch (); } Output: The first 10 odd nos. are =1, 3, 5, 7, 9, 11, 13, 15, 17, 19. Programs of For Loop (Fibonacci Series)
  • 23.
    33. W.A.P toenter the value of a & b? # include <stdio.h> # include <conio.h> void main () { int a=0, b=1, c, i; for (i=1; i<=10; i++) { printf (“%d”, a); c=a+b; a=b; b=c; } getch (); } Output: 112358132134 34. W.A.P to find sum of n Numbers? # include <stdio.h> # include <conio.h> void main () { int a, i, sum=0; clrscr (); printf (“enter the value of n”); scanf (“%d”, &n); for (i=1; i<=n; i++) { sum=sum+i; }
  • 24.
    printf (“%d”, sum); getch(); } Output: Enter the value of n=4 Answer: 10 35. W.A.P to get factorial of no.? # include <stdio.h> # include <conio.h> void main () { int num, fact=0, i; printf (“enter any no.”); scanf (“%d”, &num); for (i=num; i>=1; i--) { fact =fact*i; } printf (“factorialof a no. is %d”, fact); getch (); } Output: Enter any no. =4 Fact. Of a no is 0. 36. W.A.P to make a table of any no.? # include <stdio.h> # include <conio.h> void main () { int num, i, product;
  • 25.
    clrscr (); printf (“enterthe value of num”); scanf (“%d”, &num); for (i=1; i<=10; i++) { product= num*i; printf (“n %d*%d=%d”, num, i, prod.); } getch (); } Output: Enter the value of num 2 2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 2*10=20 37. W.A.P to find the power of the number? # include <stdio.h> # include <conio.h> Void main () { Inty, x, prod=1, I; clrscr (); printf (“Enter the value of x & y’);
  • 26.
    scanf (“%d%d”, &x,&y); for (i=1; i<=y; i++) { prod =prod*x; } printf (“%d”, prod); getch (); } Output: Enter the value of x=5, y=2: - 25 38. W.A.P to find the sum of square of a number? # include <stdio.h> # include <conio.h> Void main () { Inty, I, prod, sum=0; Clrscr (); For (i=1; i<=5; i++) { Prod =i*i; Sum =sum+ prod; } Printf (“%d”, sum); Getch (); } Output: 55. 39. W.A.P to find sum and average of n numbers? # include <stdio.h> # include <conio.h> Void main () { int n, i, num=0, average;
  • 27.
    clrscr (); printf (“Enterthe value of n”); scanf (“%d”, &n); for (i=1; i<=n; i++) { num = num + I; } printf (“Sumis %d”, num); average= num/n; printf (“n Average is %d”, average); getch (); } Output: Enter the value of n = 40 Sum is 820 Average is 20. 40. W.A.P to find reverses of a number? # include <stdio.h> # include <conio.h> void main () { int n, r=0; printf (“enter any no.”); scanf (“%d”, &n); while (n! =0) { r=r*10; r=r+n%10; n=n/10; } printf (“reverseof a no. is %d”, r);
  • 28.
    getch (); } Output: Enterany no. 123 Reverse of a no. is 321. 41. W.A.P to find palindrome of a no.? # include <stdio.h> # include <conio.h> Void main () { Intn, r=0, temp; Printf (“Enter any number”); Scanf (“%d”, &n); Temp=n; While (temp! =0) { R=r*10; R=r+temp%10 Temp=temp/10; } If (n==r) Printf (“No. is palindrome”); Else Printf (“No. is not palindrome”); Getch (); } Output: Enter any number 121 No. is palindrome Or Enter any number 122 No. is not palindrome
  • 29.
    Difference b/w WhileLoop & Do While Loop While Loop Do While Loop Condition is check first and then control goes into the loop. Condition is checked but one time loop gets executed. It is called entry control loops. It is called exit control loops. 42. Draw the Pattern: - 11111 22222 33333 44444 55555 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=1; i<=5; i++) { Printf (“n”); For (j=1; j<=5; j++) { Printf (“%d”, i); } }
  • 30.
    Getch (); } Output: 11111 22222 33333 44444 55555 43.Draw a pattern: - 1 22 333 4444 55555 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=1; i<=5; i++) { Printf (“n”); For (j=1; j<=1; j++) { Printf (“%d”, i); } } Getch ();
  • 31.
    } Output: 1 22 333 4444 55555 44. Drawthe pattern: - 55555 4444 333 22 1 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=5; i>=1; i--) { Printf (“n”); For (j=1; j<=I; j++) { Printf (“%d”, i); } } Getch (); }
  • 32.
    Output: 55555 4444 333 22 1 45. Drawthe pattern: - 12345 1234 123 12 1 # include <stdio.h> # include <conio.h> Void main () { Int i, j; Clrscr (); For (i=5; i>=1; i--) { Printf (“n”); For (j=1; j<=I; j++) { Printf (“%d”, j); } } Getch (); }
  • 33.