4 3 2 1
3 2 1
2 1
1 Program: #include<stdio.h> #include<conio.h> void main() { int r, p, k,g=0; clrscr(); printf("\n enter the no of row"); scanf("%d", &r); for ( k = r ; k >= 1 ; k-- ) { for ( p = 1 ; p <= g; p++ ) printf(" "); g++; for ( p = r;p >0 ; p --) printf("%d", p); r--; printf("\n"); } getch(); } Output:
1
12
123
1234
12345 Program: #include<stdio.h> #include<conio.h> void main() { int r, p, k,g=0,h=1; clrscr(); printf("\n enter the no of row"); scanf("%d", &r); for ( k = r ; k >= 1 ; k-- ) { for ( p = --r; p >0; p--) printf(" "); for ( p = 1;p <=h ; p++) printf("%d", p); h++; printf("\n"); } getch(); } Output:
1
23
456
78910 Program: #include<stdio.h> #include<conio.h> void main() { int r, p, k,h=1; clrscr(); printf("\n enter the no of row"); scanf("%d", &r); for ( k = 1 ; k <= 5 ; k++ ) { for ( p =1; p <=k; p++,h++) printf("%d", h); printf("\n"); } getch(); } Output:
Program: #include<stdio.h> #include<conio.h> void main() { int no[100],i,n,high=32767;//maximum possible value in signed integer clrscr(); printf("\n enter the no of no "); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&no[i]); if(high>no[i]) high=no[i]; } printf("\n the %d is smaller",high); getch(); } Output:
Program: #include<stdio.h> #include<conio.h> void main() { int no[100],i,n,high=0; clrscr(); printf("\n enter the no of no "); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&no[i]); if(high<no[i]) high=no[i]; } printf("\n the %d is greater",high); getch(); } Output:
Program: #include<stdio.h> #include<conio.h> void main() { int no1,no2,no3; clrscr(); printf("\n enter the no1,no2 and no3 "); scanf("%d%d%d",&no1,&no2,&no3); if(no1>no2&&no1>no3) printf("\n the %d is greater",no1); else if(no2>no3) printf("\n the %d is greater",no2); elseprintf("\n the %d is greater",no3); getch(); } Output:
Program: #include<stdio.h> #include<conio.h> void main() { int no1,no2; clrscr(); printf("\n enter the no1 and no2 "); scanf("%d%d",&no1,&no2); if(no1>no2) printf("\n the %d is greater",no1); elseprintf("\n the %d is greater",no2); getch(); } Output:
Program: #include<stdio.h> #include<conio.h> void main() { int no1,temp1,sum=0,n; clrscr(); printf("\n enter the no "); scanf("%d",&no1); temp1=no1; while(no1!=0) { n=no1%10; sum=sum+n*n*n; n01=no1/10; } if(sum==temp1) printf("\n the %d is armstrong",temp1); elseprintf("\n the %d not armstrong",temp1); getch(); } Output:
What is Armstrong no ?
the no is said to be armstrong if satisfy the following condition ,i.e 153=1*1*1+5*5*5+3*3*3
Program: #include<stdio.h> #include<conio.h> void main() { int no1,no2,temp,temp1,temp2; clrscr(); printf("\n enter the two no decesending order "); scanf("%d%d",&no1,&no2); temp1=no1; temp2=no2; while(no2!=0) { temp=no1%no2; no1=no2; no2=temp; } if(no1==1) printf("\n the %d and %d is co-prime",temp1,temp2); else printf("\n the %d and %d is not co-prime",temp1,temp2); getch(); } Output:
What is co-prime ?
The 2 no which has highest common factor as 1 is called co-prime.
Program: #include<stdio.h> #include<conio.h> void main() { int n,i,x=0; clrscr(); printf("\nEnter the no"); scanf("%d",&n); for(i=2;i<=n/2;i++) { if(n%i==0) x++; } if(x>1) printf("\n the %d is prime",n); else printf("\n the %d is not prime",n); getch(); } Output What is prime no?
the number which is not divisible by any other no except that no is called prime no
Program: #include<stdio.h> #include<conio.h> void main() { int n1=0,n2=1,n,sum=0; clrscr(); printf("\nEnter the limit of the series"); scanf("%d",&n); printf("\n%d",n1); printf("\n%d",n2); while(sum<n) { sum=n1+n2; n1=n2; n2=sum; printf("\n%d",sum); } getch(); } Output: What is Fibonacci series ?
the series which is obtained by addition of two previous no is called Fibonacci series.
Problem:
we have to write a program that will display the text in color and also their background in color
Solution:
the conio.h header file has the in build function to print the text in color ,below table show available color and their value, whether it can be used for background and foreground . Program coding:
#include <conio.h> void main() { int i,j; clrscr(); for (i=0,j=9; i<9; i++,j--) { cprintf("\r\nC4engineer.blogspot.com\r\n"); textcolor(i+1); textbackground(j+1); } getch(); } Output:
Problem:
Program to moving the text horizontally , for this purpose we need to know the width of the output screen, so that we make an circular rotation.to see the movement of text without specifying width of the screen. Solution: //width of the output screen #include<stdio.h> #include <conio.h> #include<dos.h> int main(void) { int x=0; clrscr(); while (!kbhit() { clrscr(); gotoxy(x, 12); printf("Hello world"); delay(100);//delay the control flow x++; if (x>=81)//width of the screen { x=0;//once it reach end of the screen , reset to beginning } } printf(" /n width of the screen %d",x); getch(); return 0; }
In all our program we use the clrscr() and getch() function irrespective of what program it is ,if you don’t use it in your program you didn’t get any error, it has some effect on the output display not on the out clrscr :
clrscr means clear screen, i will clear the output of the previous program(s) . below fig, show the effect of clrscr on the output when it is not used
from the above image we can see that current program output is displayed along with previous output. getch:
getch means get character, this command hold the output screen till the user press any key, without this command user cannot see the output after running the program(ctrl+F9), (can see by pressing alt+F5,after running the program). see the below video
Problem:
To find whether the given no is perfect square or not . this so simple to find int and float float value of square root no is same if and only if that no is perfect square, example int sqrt of 2 is 1 and that of float is 1.414,
Solution: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int s1,no; float s2; clrscr(); printf("\n enter the no "); scanf("%d",&no); s1=sqrt(no); s2=sqrt(no); if(s1==s2) printf("\n the given no %d is square",no); else printf("\n the given no %d is not square",no); getch(): }
Problem :
find the given string is palindrome or not without using string.h header file , why this condition is given because without string.h header file we cannot use any function like strlen,strcmp,strcpy,strrev.
Solution:
#include<stdio.h> #include<conio.h> void main() { char a[100],i,j,equal=0,k; clrscr(); printf("\n enter the string "); scanf("%s",a); for(i=0;a[i]!='\0';i++); for(j=i-1,k=0;a[k]!='\0';j--,k++) if(a[j]==a[k]) equal++; if(equal==i) printf("\n the %s is palindrome",a); else printf("\n the %s is not palindrome",a); getch(); }
Problem:
Swap the 2 number without using any third variable . Solution: #include<conio.h> #include<stdio.h> void main() { int a, b; clrscr(); printf("\n enter the two no "); scanf("%d%d",&a,&b); printf("before swape \n A=%d B=%d",a,b); a=a+b; b=a-b; a=a-b; printf("\nafter swape \n A=%d B=%d",a,b); getch(); }
whenever you open turbo c editor it provide the full screen mode , you only minimize it to taskbar, please follow the procedure below to reduce size of c editor window
step 1) open the turbo c, then minmize it to taskbar
step 2) right click minimized turbo c then select property ,
you can see the window like this
step 4) in the display option select window ,then press ok .see image below.
step 5) you will get apply properties window, select save properties for future window with same tilte,then press
that's all now you can see the window in reduced size , see image below
Problem :
Find Greatest Common divisor for given two no, ex 22 and 33 HFC is 11
Solution:
#include<stdio.h> #include<conio.h> void main() { int no1,no2,temp; clrscr(); printf("\n enter the two no decesending order "); scanf("%d%d",&no1,&no2); while(no2!=0) { temp=no1%no2; no1=no2; no2=temp; } printf("\n the highest comman factor is %d",no1); getch(); } Output:
Problem:
Write a program to no of words in given line , ex give line is "Welcome you All" and result should be printed as 3 Solution: #include<stdio.h> #include<conio.h> void main() { char a[100]="this is c language ",i,j,count=0,need_word=1,isalphabet; clrscr(); printf("\n%s",a); for(i=0;a[i]!='\0';i++); for(j=0;j<i;j++) { if((a[j]>='a'&&a[j]<='z')||(a[j]>='A'&&a[j]<='B')) isalphabet=1; else isalphabet=0; if(isalphabet) { if(need_word) { count++; need_word=0; } } else need_word=1; }
printf("\nthe length of the string is %d",count); getch(); }
Problem:
To find the length of the given string without using any strlen function
Solution: #include<stdio.h> #include<conio.h> void main() { char a[100],i,j; clrscr(); printf("\nenter the string without space"); scanf("%s",a); for(i=0;a[i]!='\0';i++); printf("the length of the string is %d",i); getch(); }
Problem:
To convert the given decimal no into binary or octal or hexadeciaml with menu option , if user enter the base 8 it should be converted into octal
Solution:
#include<stdio.h> #include<conio.h> void main() { int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j,base; clrscr(); printf("\n enter the no .."); scanf("%d",&a); printf("\n enter the base \nBinary--->2\nOctal--->8\nHexadecimal--->16"); scanf("%d",&base); while(a!=0) { data[i]=a%base; i++; a=a/base; } for(i--;i>=0;i--) { j=data[i]; if(j<=9) printf("%d",intex[j]); else printf("%c",intex[j]); } getch(); }
Problem:
To convert the given decimal no into Hexadecimal without using in build function ,Example 26 shoule printed as 32
Solution:
#include<stdio.h> #include<conio.h> void main() { int a,b,intex[]={0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'},data[100],i=0,j; clrscr(); printf("\n enter the no .."); scanf("%d",&a); printf("\nthe %d to binary is ",a);
To convert the given decimal no into octal without using in build function ,Example 26 shoule printed as 32
Solution:
#include<stdio.h> #include<conio.h> void main() { int a,b,intex[]={0,1,2,3,4,5,6,7},data[100],i=0,j; clrscr(); printf("\n enter the no .."); scanf("%d",&a); printf("\nthe %d to octal is ",a);
Problem
To convert the given decimal no into binary without using in build function , exampla 11 to printed as 1011
Solotion #include<stdio.h> #include<conio.h> void main() { int a,b,intex[]={0,1},data[100],i=0,j; clrscr(); printf("\n enter the no .."); scanf("%d",&a); printf("\nthe %d to binary is ",a);
Problem:
Find asked greatest no in the given array without using sorting algorithm, example the array is 1,2,4,5 ,6,5,7
asked greatest no is 3 then it should print 5, if it asked 2nd greatest no then it should print 6. Solution
#include<stdio.h> #include<conio.h> void main() { int i,j,no[100],n,in,high=0; clrscr(); printf("enter the no of no"); scanf("%d",&n); printf("enter the no one by one"); for(i=0;i<n;i++) scanf("%d",&no[i]); printf("enter the which high no you need"); scanf("%d",&in); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(no[i]>no[j])
high++; } if(high==n-in) { break; } high=0; } printf("the %d big no is %d",in,no[i]); getch(); } Output
//Palindrome Program #include<stdio.h> #include<conio.h> void main()
{ int n,no,rno=0,dno;
clrscr();
printf("enter the no");
scanf("%d",&no);
dno=no; while(no!=0)
{
n=no%10;
rno=rno*10+n;
no=no/10;
} if(dno==rno)
printf("the %d is palindrome ",dno); else
printf("the %d is not palindrome",dno);
getch();
} Output
What is Palindrome number ?
The no is said to palindrome whose direct view and mirror view are same, example take 121 , whose mirror image is 121 so 121 is palindrome.
out of the above mention Header File mostly used Header File at beginning level is
<stdio.h>
<conio.h>
<strings.h>
<math.h> Hear file <stdio.h>
This header file is used in every program because it include the definition of printf, scanf getc,getchar,putc,putchar etc.
see the fig below
we can see that without stdio.h header file , the compiler cannot identify the definition of printf . Hear file <conio.h>
This header file is used in every program because it include the definition of clrscr, getch ,ungetch,putch,gotoxy, etc.
see the image below
we can see that without conio.h header file , the compiler cannot identify the definition of clrscr and getch .
Header file <math.h>
To include the inbuile mathematical function like cos,sine, log, sqrt(square root), we need to
include the header file <math.h>
header file <string.h>
this header file used for string (sequence of character) hadling,and manipulation like strlen,strcpy,strcat etc
C is called structure programming language , because it is strictly restricted to its sructure . anything out of its structure is not accepted .
Structure of C
Header File
Sub Function Declaration
Global variable
main Function Definition
{
Local variable
Content of Main Function
}
Sub Function Definition
{
Local variable
Content of Sub Function
}
Example
#include<stdio.h> #include<conio.h> int sum; void sum(int c,int d); void main()
{ int a=10,b=20;
clrscr();
sum(a,b);
printf(" The Sum is %d ",sum);
getch();
} void sum(int c,int d)
{
sum=c+d;
}
The data type int, printf are defined in STDIO header file . STDIO stands for Standard input and output .
clrscr(); getch() are defined in CONIO header file . CONIO stands Console Input Output . the Variable SUM is known as Global variable and its scope (lifetime) is throughout program . where as variable a and b is local variable its scope(lifetime) is with that function only . so in the above Program SUM is used in sub function and Main fuction .
Out of Structure Program
The program which doesn't follow the above structure is not accepted by c compiler , it will show an error .
the example of out of structure program is shown below #include<stdio.h> #include<conio.h> void sum(int c,int d); void main()
{ int a=10,b=20,sum;
clrscr();
sum(a,b); int s;
s=sum;
printf(" The Sum is %d ",s);
getch();
} void sum(int c,int d)
{
sum=c+d;
}
In the above program variable Sum is used in both main as well as subfunction , so it is Global variable , so it should defined below the header file, the variable c is declared in the middle of the program but as per C structure it should be declared in the beginning . so when above code is compiled by c compiler it show an error