*Programming For Beginners ::
* Programming is all about your interest and the way you take it in your life.
* From the very basic to the recent HTML/CSS , Javascript , Ajax ,Python ,Java , C# ,Ruby, .Net
logic is same but the integration is advanced.
* Logic part can be understood by using your mind rather than copying and pasting.
* Why don't we give a damn chance to our mind to think in a different manner.
************* C PROGRAMMING **********
* Functions :- thing responsible to do anything logically.
* Main :- body part is enclosed within main a program can contain several main function.
********************************************************************************
Header files and Functions
********************************************************************************
Header files and functions:
* Programming is all about your interest and the way you take it in your life.
* From the very basic to the recent HTML/CSS , Javascript , Ajax ,Python ,Java , C# ,Ruby, .Net
logic is same but the integration is advanced.
* Logic part can be understood by using your mind rather than copying and pasting.
* Why don't we give a damn chance to our mind to think in a different manner.
************* C PROGRAMMING **********
* lets take a simple example:-
#include <stdio.h> //header file standard input output library.header file
#include <conio.h> // console input output .header file
void main()
{
clrscr(); //clear screen
printf("my name is anshuman kumar");//function used to print something on the console
getch(); //function used for w8ng for the next key stroke generated from user
}
>>>>>output::my name is anshuman kumar
* Till now we have five things in the picture
1. pre processor directive(#)
2. LIbrary
3. Header files
4. Functions
5. Main
* PreProcessor directives(#):-It tells the compiler to include the header file
* Header file:- function declaration is there in header file.contains the name of the
function only.#include <stdio.h> //header file standard input output library.header file
#include <conio.h> // console input output .header file
void main()
{
clrscr(); //clear screen
printf("my name is anshuman kumar");//function used to print something on the console
getch(); //function used for w8ng for the next key stroke generated from user
}
>>>>>output::my name is anshuman kumar
* Till now we have five things in the picture
1. pre processor directive(#)
2. LIbrary
3. Header files
4. Functions
5. Main
* PreProcessor directives(#):-It tells the compiler to include the header file
and the function associated.
* Library:- ( function definition is here.) Always known as the reference.all
the standard function is
* Library:- ( function definition is here.) Always known as the reference.all
the standard function is
defined over here.
* Header file:- function declaration is there in header file.contains the name of the
* Functions :- thing responsible to do anything logically.
* Main :- body part is enclosed within main a program can contain several main function.
********************************************************************************
Header files and Functions
********************************************************************************
Header files and functions:
<stdio.h>:-provide the input output functionality to
the end user.
<conio.h>:-console related function(screens i.e output
screen related functions).
<string.h>:-For manipulation with the strings.
<assert.h>:-
Used to handle the common logical errors in the programme.
<math.h>:- For
computing common mathematical logic.
<ctype.h>:-To undersatand character by their type and
the conversion from lower case to upper
case.
<signal.h>:-To control the exceptional condition.
<stdlib.h>:-Memory allocation, Proceess control,
<time.h>:-For converting various date and time
formats.
<stdio.h>:- functions
Scanf()
|
used for input the data from the end user side.
|
Printf()
|
printing on the console screen.
|
Gets()
|
Read characters from stdin while a new line is inserted
|
Putc()
|
writes and returns a character to a stream
|
Putchar()
|
Works same as putc()
|
Puts()
|
Output a string on the standard output.
|
Fopen()
|
Open the file for reading and writting
|
Fwrite()
|
Writing in the file
|
Fputs()
|
Placing string in the file
|
Remove ()
|
Deleting a file
|
Rename()
|
Renaming a file
|
<Conio.h>:-
Clrscr():
|
Used for clearing the screen
|
Getche():
|
W8 for the next key stroke
generated from user
|
Getch():
|
|
Getc():
|
<math.h>
Cos()
|
cosine of the value ….[cos(10)]
|
Log()
|
logarithm value ……….[log(10)]
|
Pow()
|
power function …… ..[pow(2,4)=16]
|
Sqrt()
|
square root…………….[sqrt(4)=2]
|
Tan()
|
gives tangent …………..[tan(value)=output]
|
Ceil()
|
small integer…… ……..[ ceil ( 5.6 )= 5]
|
Floor()
|
largest integer……….[floor (5.6)=6]
|
<Ctype.h>
Islower()
|
Checks for lower case
|
Isupper()
|
Checks for the upper case
|
Isspace()
|
Checks for the whitespace
|
Isxdigit()
|
Checks for the hexadecimal digit
|
Isdigit()
|
Checks for the digit
|
Isgraph()
|
Checksfor the graphics
|
Isprint()
|
Checks for the print charecter
|
<Time.h>
Difftime()
|
Returns difference between two time perio
|
Clock()
|
Clock program
|
Mktime()
|
Convert tm to current time
|
Time()
|
Get current time
|
<
string.h>
Strlen()
|
Returns the length of selected string
|
Strupr()
|
Returns the uppercase string
|
Strlwr()
|
Returns the lowercase strings
|
Strcmp()
|
Comparing the two string
|
Strcat()
|
Concatenating the string
|
Strrev()
|
Reversing the string
|
Strcpy()
|
Copyng the string
|
*********************************************************
·
Wap (write a prgram to calculate the roots of quadratic equation)
1.
#include<stdio.h>
2.
#include<conio.h>
3.
#include<math.h>
4.
Void main()
5.
{
6.
Clrscr();
7.
8.
float
b,a,c,Root1,Root2;
9.
Printf(“quadratic equation program”);
10.
Printf(“enter the element ’a’,’b’,’c’”);
11.
12.
Scanf(“%f,%f,%f”,&a,&b,&c);
13.
If( b*b>=4*a*c )
14.
{
15.
Root1=(-b-sqrt(b*b-4*a*c))/2*a;
16.
Root2=(-b+sqrt(b*b-4*a*c))/2*a;
17.
Printf(“Roots of the quadratic
equation=%f,%f ”,Root1,Root2);
18.
}
19.
Else
20.
{
21.
Printf(“imaginary roots”)
22.
}
23.
getche();
24.
}
Line 8.. contains the datatype and the variable for the the
programme…
Logic 1:formulae=-b-squareroot of(b*b-4*a*c)whole divided by
2a
Logic 2:formulae=-b+squareroot of(b*b-4*a*c)whole divided by
2a
****Datatypes****
Bool,Byte
,char,long,short,int,float,double etc
((prefer the book regarding datatype,literals,keywords,
variables,how to declare the variable topics))
Wap
for the calculation implementation::
1.
#include<stdio.h>
2.
#include<conio.h>
3.
#include<math.h>
4.
Void main()
5.
{
6.
Clrscr();
7.
Int
no1,no2,add,substract,multiply,divide,ramainder;
8.
Printf(“\n enter the two nos”);
9.
Scanf(“%d,%d”,&no1,no2);
10.
add=no1+no2;
11.
substract=no1-no2;
12.
multiply=no1*no2;
13.
divide=no1/no2;
14.
remainder=no1%no2;
15.
printf(“\nsumof %d and %d=”,no1,no2,add );
16.
printf(“\nsubstraction of %d and
%d=”,no1,no2,substract );
17.
printf(“\ndivision of %d and %d=”,no1,no2,divide
);
18.
printf(“\nmultiplication of %d and
%d=”,no1,no2,multiply);
19.
printf(“\nremainder of %d and
%d=”,no1,no2,remainder );
20.
getche();
21.
}
Wap to
demonstrate the simple interest:-
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
Clrscr();
6.
float
p,r,t,si,amount;
7.
printf(“\nenter the principle rate and time
respectively”);
8.
scanf(“%f%f%f”,&p,&r,&t);
9.
si=(p*r*t)/100.0;
10.
amount=p+si;
11.
printf(“ \nsimple interest=”,si);
12.
printf(“\n Amount=”,amount);
13.
getche();
14.
}
Wap to demonstrate the power function
and square root function:
1.
#include<stdio.h>
2.
#include<conio.h>
3.
#include<math.h>
4.
Void main()
5.
{
6.
Clrscr();
7.
Int a=2,b=5;
8.
Float c;
9.
c=pow(a,b);
10.
Printf(“2 to the power 5=”,c);
11.
c=pow(a,pow(a,b));
12.
printf(“2 to the powerof 2 to the power5=”,c);
13.
c=Sqrt(a*b);
14.
printf(“squareroot of2*5=”,c);
15.
16.
getche();
17.
}
Wap in c to find the average of salary
of the n no of ppl n is provided by the
user
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
clrscr();
6.
int n,i=1;
7.
float
no,sum=0,avg;
8.
printf(“\n enter the total no of element”);
9.
scanf(“%d”,n);
10.
while(i<=n)
11.
{
12.
printf(“enter the number”);
13.
scanf(“%f”,no);
14.
sum=sum+no;
15.
i++
16.
}
17.
avg=sum/n;
18.
printf(“average of%d no is %f”,n,avg);
19.
getche();
20.
}
·
Line 7 :sum =0 its due to the garbage value it can take from the
other program for the accurecy. we intially make these kind of element 0 or 1
depending on its nature.
·
Line 11 :while loop checking the condition
sequentially .
·
Line14:summing up the all noone by one as
entered from user.
·
Line 15:as ones processing is done i is an
increment operator it is incremented by 1 i.e i++ or i=i+1.
·
Suppose we have to find the average of 3 ppl
salary
·
i=1, sum=o, n=3
·
i<=n (1<=3)true
·
no=1000, sum=0+1000,i=2
·
sum=1000,i=2
·
i<=n(2<=3)true
·
no=3000,sum=1000+3000,i=3
·
sum=4000,i=3
·
i<=n(3<=3)true
·
no=5000,sum=4000+5000,i=4
·
now i=4 sum=9000
·
i<=n(4<=3)false come out of the loop
·
avg=sum/n;
·
avg=9000/3=3000
wap
for the factorial : (while and for loop
seperately)
1.
#include<stdio.h>
2.
#include<conio.h>
3.
void main()
4.
{
5.
clrscr();
6.
int
i,no,fact=1;
7.
printf(“\nenter the no:”);
8.
scanf(“%d”,&no);
9.
i=no;
10.
while(i!=0)
11.
{
12.
fact=fact*i;
13.
i--;
14.
}
15.
Printf(“\nfactorial of%d=%d”,no,fact)
16.
getche
17.
}
Line 8:user input the no assigned to the some variable i.
Line 10:while loop is used along wid the logic: (i!=0) i.e i
is not equal to zero condition is true in that case otherwise when it turns to zero
processing will come out of the loop.
Line 12,13:fact=fact*i
it will continously wrap the data in the one cycle and waits
for the another cycle.
Now take an example and try to
understand the concept:
1.
Enter the no:3
2.
i=3
3.
i!=0,3!=0,condition true enter in the loop
4.
fact=fact*I; fact=1*3;fact=3
5.
i- - i.e i=i-1;i=3-1=2;
6.
now i=2,fact=3
7.
check condition i!=0 true;
8.
go in the loop fact=fact*I; i.e,fact=3*2=6
9.
fact=6;i=1
10.
check
i!=0 true
11.
go in the loop fact=fact*i;fact=6*1;fact=6
12.
fact=6 ,i=0;
13.
check i!=0 false
14.
come out of loop,here fact=6.
15.
Factorial of 3=6;
Same
by for loop
1.
#include <stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
Clrscr();
6.
int
no,i,fact=1;
7.
printf(“\n enter the no”);
8.
scanf(“%d”,&no);
9.
10.
for(i=no; i >=1 ;i-- )
11.
{
12.
fact=fact*I;
13.
}
14.
printf(“\nfactorial of%d=%d”,no,fact);
15.
getche();
16.
}
For loop( initialisation of variables ; condition ; increment/decrement
of variable )
Wap
for no enterd odd or even:
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
Clrscr();
6.
int no;
7.
printf(“\n enter the no”)
8.
scanf(“%d”,&no);
9.
if(no%2==0)
10.
{
11.
Printf(“\nno is even”);
12.
}
13.
Else
14.
Printf(“\nno is odd”)
15.
Getche();
16.
}
Wap
for adding the digit of the given number:
1.
#include<stdio.h>
2.
#include<conio.h>
3.
void main()
4.
{
5.
Clrscr();
6.
int
no,I,sum=0,m;
7.
printf(“\nenter the no”);
8.
scanf(“%d”,&no);
9.
i=no;
10.
11.
While(i!=0)
12.
{
13.
m
=i%10;
14.
sum=sum+m;
15.
i=i/10;
16.
}
17.
18.
Printf(“\nsum of the digits of the no
%d=%d”,no,sum);
19.
Getche();
20.
}
Take an example no=234;
1.
No=234,sum=0
2.
i=234,sum=0
3.
condition true
4.
m=i%10;m=234%10=4;
5.
m=4,sum=0+4;
6.
i=i/10=234/10;i=23
7.
i=23,sum=4
8.
check condition true
9.
m=i%10=23%10=3
10.
sum=4+3;
11.
i=2,sum=7
12.
check condition true
13.
m=2%10=2
14.
sum=7+2,i=0
15.
check condition false
16.
sum=9
wap
swapping(with variable without variable)
with
variable
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
Clrscr();
6.
int a=5,b=10,c;
7.
printf(“a=%d,b=%d”,a,b);
8.
c=b;
9.
b=a;
10.
a=c;
11.
printf(“after swapping a=%d,b=%d”,a,b);
12.
getche();
13.
}
Without
variable
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{ clrscr()
5.
Int a=10,b=5;
6.
a=a+b;
7.
b=a-b;
8.
a=a-b;
9.
printf(“\nafter swapping a=%d,b=%d”,a,b);
10.
getche()
11.
}
Wap
for reversing the number
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
Clrscr();
6.
Printf(“\nprogram for revershing the
number”);
7.
8.
int
no,i,m,revno=1;
9.
10.
Printf(“\nenter the number”);
11.
Scanf(“%d”,no);
12.
i=no;
13.
While(i!=0)
14.
{
15.
m=i%10;
16.
revno=revno*10+m
17.
i=i/10;
18.
}
19.
Printf(“\n revno:%d”,revno);
20.
getche();
21.
}
Wap for the design like this
A
An
Ans
Anshu
Anshuman
1.
#include<stdio.h>
2.
#include<conio.h>
3.
void main()
4.
{
5.
char string[100];
6.
int i,k,length;
7.
printf(“\n enter the string”);
8.
gets(string);
9.
length=strlen(string);
10.
for(i=0;i<length;i++)
11.
{
12.
for(k=0;k<=I;k++)
13.
{
14.
Printf(“%c”,string[k]);
15.
}
16.
Printf(“\n”);
17.
}
18.
getch();
19.
}
Wap
for the palindrome no
1.
#include<stdio.h>
2.
#include<conio.h>
3.
Void main()
4.
{
5.
clrscr();
6.
int
no,reverse_no=1,m,I;
7.
printf(“\n enter the no”);
8.
scanf(“%d”,&no);
9.
i=no;
10.
11.
while(i!=0)
12.
{
13.
m=i%10;
14.
reverse_no=reverse_no * 10+m;
15.
i=i/10;
16.
}
17.
18.
19.
20.
If(reverse_no==no)
21.
{
22.
Printf(“\n the no entered is a palindrome”);
23.
}
24.
Else
25.
{
26.
Printf(“\n the no entered is not a
palindrome no”);
27.
}
28.
29.
}
Logic is same as reversing the number and if the reversed no is
equal to the actual no then it’s a palindrome else not.
·
·
No comments:
Post a Comment