Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Friday 21 June 2019

Thursday 20 June 2019

C Program for Addition of Two Numbers

Program for addition of two numbers
 
                    


Output:
       


Code :-


#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b,c;
printf("Enter a number:\n");
scanf("%d",&a);
printf("Enter another number:\n");
scanf("%d",&b);
c=a+b;
printf("The Sum is : \n=%d ",c);
return 0;
}

Monday 17 June 2019

Lecture 9 - While Loop Example GCD

While Loop Example GCD                                                                                                                                                                                                          
                                                                                                             

Lecture 8 - While Loop Example

While Loop Example                                                                                                                                                                 


Lecture 7 - While Loop 1

While Loop Example                                                                                                                                                              
In this lecture we will learn about introduction to while loop.                                                                                                                                                                                                                                                

Saturday 15 June 2019

Lecture 6 :- Operators in C

Operators in C                                                                                                           
In this lecture we will learn about different types of operators in C.                                                                                                                                                                  


Lecture 5 :- Variables in C

Variables in C                                                                                                                                                                                                                            
In this lecture we will learn about variables in C                                                                                                                   

Lecture 4 Tracing a Simple Program

 Tracing a Simple Program

  In this video we will learn  how to write a basic program in C.How to run a program in C.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

Lecture 3 :- The Programming Cycle

The Programming Cycle


In this video we will learn about what are the basics steps to run a program in C                                                                                                                                                                                                           

Lecture 2: Introduction to Greatest Common Divisor


In this video you will learn about Euclid's Greatest Common Divisor (Theorem) and its relation with C language.We will also learn some basics step to run a program.                                                                                                                                     


Wednesday 27 March 2019

Beginning C, 5th Edition (Expert's Voice in C) by Ivor Horton (Author)

Beginning C, 5th Edition teaches you how to program using the widely-available C language. You'll begin from first-principles and progress through step-by-step examples to become a competent, C-language programmer. All you need are this book and any of the widely available free or commercial C or C++ compilers, and you'll soon be writing real C programs.
C is a foundational language that every programmer ought to know. C is the basis for C# used in Microsoft .NET programming. It is the basis for Objective-C used in programming for the iPhone, the iPad, and other Apple devices. It is the basis for the C++ that is widely used in a great many contexts, including the GNU Project. It underlies the Linux operating system and many of its utilities. Learning C provides a strong foundation for any programming care, and will even help you better understand more modern languages such as Java.
Beginning C is written by renowned author Ivor Horton. The book increases your programming expertise by guiding you through the development of fully working C applications that use what you've learned in a practical context. You’ll also be able to strike out on your own by trying the exercises included at the end of each chapter. At the end of the book you'll be confident in your skills with all facets of the widely-used and powerful C language.
  • The only beginning-level book to cover the latest ANSI standard in C
  • Revised to cover C99 features newly-supported by language compilers
  • Emphasizes writing code after the first chapter
  • Includes substantial examples relevant to intermediate users 

Buy :
Beginning C, 5th Edition (Expert's Voice in C) Paperback – 13 Mar 2013 by Ivor Horton (Author) 

PDF Download :

Beginning C, 5th Edition (Expert's Voice in C) Paperback – 13 Mar 2013 by Ivor Horton (Author) 




Head First C Paperback – 2012 by Griffiths David (Author)

Ever wished you could learn C from a book? Head First C provides a complete learning experience for C and structured imperative programming. With a unique method that goes beyond syntax and how-to manuals, this guide not only teaches you the language, it helps you understand how to be a great programmer. You will learn key areas such as language basics, pointers and pointer arithmetic and dynamic memory management. Advanced topics include multi-threading and network programming topics typically covered on a college-level course.

This book also features labs: in-depth projects intended to stretch your abilities, test your new skills and build confidence. Head First C mimics the style of college-level C courses, making it ideal as an accessible textbook for students.

We think your time is too valuable to waste struggling with new concepts. Using the latest research in cognitive science and learning theory to craft a multi-sensory learning experience, Head First C uses a visually rich format designed for the way your brain works, not a text-heavy approach that puts you to sleep.

Buy :

Head First C Paperback – 2012 by Griffiths David (Author) 

PDF Download :



Tuesday 26 March 2019

C Programming Language 2nd Edition by Brian. W Kernighan (Author)

C Programming Language 2nd Edition is a book that gives you just what you need to know about this powerful programming language. Unlike most of its rivals, which try to pack in irrelevant information as well, this book comes jam-packed with the most accurate and handy information that any lover of this programming language could possibly need. This second edition is inclusive of all the changes that have come about in the language, making the book a powerful resource for its readers.
This book proves itself to be a complete and accurate guide for ANSI standard C programming language. It has been written by the very same developers who developed C, which is beneficial for its readers, as it gives them the edge over other books. The book shows you exactly how you can make the most of the rich set of operators that C has to offer. It also familiarizes you with other concepts that include improved control flow, economy of expression and data structures as well.
The second edition of the book has been rewritten, so as to include many more examples than before. It also comes with problem sets that aim to clarify the doubts that you have, concerning the complicated language constructs of this language and their implementation as well.
C Programming Language 2nd Edition has been published by Pearson Education (Singapore) Pte. Ltd., in the year 2008 and is available in paperback.
Key Features

  • The book is packed with multiple examples and problem sets.
  • The recent edition of the book is inclusive of all the latest changes that have been made to the language.

Buy :

C Programming Language 2nd Edition Paperback – 2008 by Brian. W Kernighan (Author) 

PDF Download :

C Programming Language 2nd Edition Paperback – 2008 by Brian. W Kernighan (Author) 



Monday 9 April 2018

Pointer and Function

The pointers are very much used in a function. Sometimes only with a pointer a complex function can be easily represented and success. The usage of the pointers in a function defintion may be classified into two groups.
1. Call by Value.
2. Call by reference

Call by Value 
  We have seen that a function in invoked there will be a link established between the formal and actual parameters. A temporary storage is created where the value of actual parameters is stored.

The formal parameters picks up its value from storage area the mechanism of data transfer between actual parameters mechanism of data transfer is referred as call by value.

The corresponding formal parameters represents a local variable in the called function.


This will not change the value of actual parameters.

#include<stdio.h>
void main( )
{
int x,y;
x=20;
y=30;
printf("\n Value of a and b before function call = %d%d",a,b);
fucn(x,y);
printf("\n Value of a and b after function call = %d%d",a,b);
}
fucn(p,q)
int p,q;
{
p=p+q;
q=q+q;
}

Call by Reference
 When we pass address to a function the parameters  receiving the address  should be pointers. The process of calling a function by using pointers to pass the address of the variable is known as call by reference . The function which is called by reference can change the value of the variable used in the call.

/* Example of call by reference */

#include<stdio.h>
void main( )

int x, y;
x=20;
y=30;
printf("\n Value of a and b before function call = %d%d",a,b);
fucn(&x,&y);
printf("\n Value of a and b after function call = %d%d", a,b);
}
fucn(p,q)
int p,q;
{
*p=*p + *p;
*q=*q + *q;
}

Function

A function is a self contained block of statement that performs a coherent task of some kind.

Functions provides modularity to the software.

#include<stdio.h>
int add (int x, int y)
int z;
z = x + y;
return (z);
}
main( )
{
int i,j,k;
i = 10;
j = 20;
k = add(i,j)        /* function call */
printf("The value of k is %d\n",k);
}

Output:-
  The value of k is 30.
 

Pointer

In C language a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer.

Pointer Declaration :
  A pointer is a variable that contains the memory location of another variable. The syntax is as shown below. You start by specifying the type of data stored in the location identified by the pointer. The asterisk (*) tells the compiler that you are type * variable name

Example :
 int *ptr;
float *string;

Address Operator :
  Once we declare a pointer variable we must point it to something we can do this by assigning to the pointer the address the address of the variable you want to point as in the following example :
ptr=&num;
   This places the address where num is stores into the variable ptr. If num is stored in memory 21260 address then the variable ptr has the value 21260.

Memory Space of int Pointer and long double pointer
  
Size of any type of pointer is independent of the data type which it is pointing i.e. size of pointer is always fixed. Size of any type (near) of pointer in C is two byte.

For example :
 #include<stdio.h>
 void main( )
{
int *p1;
long double *p2;
printf("%d %d", sizeof (p1) , sizeof (p2) );
}

Output :   2     2

Since both pointers int and long double are pointing to only first byte of int data and long double data respectively.
   
Hence both int pointer and long double pointer stores only address in 16 bits. Thus both of the them will occupy exactly equal memory spaces.

The size of void Pointer in C :
     
Size of any type of pointer in C is independent of data type which is pointer pointing i.e. size of all type pointer (near) in C is two byte either it is char pointer double pointer, function or null pointer. Void pointer is not exception of this rule and size of void pointer is also two byte.

String Operations (string.h)

C language recognizes that string is a different class of array by letting us input and output the array as a unit and are terminated by null character. C library supports a large number of string handling functions that can be used to carry out many of the string manipulations such as :-

 * Length (Number of character in the string).
 * Concatenation (Adding two or more strings).
 * Comparing two strings.
 * Substring (Extract substring from a given string).
 * Copy (Copies one string over another).

To do all the operation described here it is essential to include string.h library header file in the program.

strlen( ) Function
  This function counts and returns the number of character in a string. The length does not include a null character.

 Syntax
 n=strlen(string);
                     Where n is integer variable which receives the value of length of the string.

Example :
  length = strlen("Irawen");
The function will assign number of character 9 in the string to a integer variable length.


\*Write a C program to find the length of the string using strlen( ) function. */

#include<stdio.h>
#include<string.h>
void main( )
{
char name[100];
int length;
printf("Enter the string");
gets(name);
length = strlen(name);
printf("\n Number of character in the string is=%d",length);
}

strcat( ) Function
 When you combine two strings , you add the character of one string to the end of other string. The process is called concatenation. The strcat( ) function joins two strings together. It takes the following form

Syntax :
  strcat(string1, string2)
   String1 and string2 are character arrays. When the function strcat is executed string2 is appended to string1. The string2 remains unchanged.

Example :
 strcpy(string1, "sri");
 strcpy(string2,"Bhagavan");
 printf("%s",strcat(string1,string2);
  
From the above program segment the value  of string1 becomes sribhagavan. The string at str2 remains unchanged as bhagavan.

strcmp( ) Function
  In C language we cannot directly compare the value of 2 strings in a condition like if(string1==string2).
  
Most libraries however contain the strcmp( ) function, which returns a zero if 2 strings are equal, or a non zero number if the strings are not the same. The syntax of strcmp( ) is given below :
       Strcmp(string1,string2)

 String1 and string2 may be string variable or string constants. String1 and string2 may be string variable or string constant some computers return a negative if the string1 is alphabetically less than the second and a positive number if the string is greater than the second.

Example :
strcmp("Newyork","Newyork")  will return zero because 2 strings are equal.

strcmp("their","there") will return a 9 which is the numeric difference between ASCII 'i' and ASCII 'r'.

strcmp("The","the") will return 32 which is the numeric difference between ASCII "T" & "t".


strcmpi( ) Function 
  This function is same as strcmp( ) which compares 2 string but not case sensitive.

Example :
  strcmpi("THE","the");  will return 0;

strcpy( ) Function
  C language not allow you to assign the characters to a string directly as in the statement name="Robert";

Instead use the strcpy( ) function found in most compilers the syntax of the function is illustrated below.
 strcpy(string1,string2);

Strcpy function assign the contents of string2 to string1. String2 may be a character array variable or a string constant.

strcpy(Name,"Robert");
In the above example Robert is assigned to the string called name.

strlwr( ) Funtion
 This function converts all characters in a string from uppercase to lower case.

Syntax:
 strlwr(string);

For example :
strlwr("IRAWEN") converts to Irawen.


strrev( ) Function
  This function reverses the character in a string.

Syntax
  strrev(string);

For example :
strrev("program") reverses the character in a string into "margrop".

strupr( ) Function
  This function converts all character in a string from lower case to uppercase.

Syntax
 strupr(string);

For example :
 strupr("pirawen") will convert the string to PIRAWEN.

/* Example program to use string functions */

#include<stdio.h>
#include<string.h>
void main( )
{
char s1[20], s2[20], s3[20];
int x;
printf("Enter the strings");
scanf("%s%s",s1,s2);
x=strcmp(s1,s2);
if(x!=0)
{
printf("\nStrings are not equal\n");
strcat(s1,s2);
}
else
printf("\nStrings are equal");
strcpy(s3,s1);
l1=strlen(s1);
l2=strlen(s2);
l3=strlen(s3);
printf("\n s1=%s\t length=%d characters\n",s1,l1);
printf("\n s2=%s\t length=%d characters\n",s2,l2);
printf("\n s3=%s\t length=%d characters\n",s3,l3);
}

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (114) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (89) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (745) Python Coding Challenge (198) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses