Sunday, 13 November 2016

Session Four

#include<stdio.h>
void main ()
{
/* int a=10,b=20,c=30;

printf ("Enter three values \n");

scanf ("%d-%d-%d",&a,&b,&c);

printf ("First number : %d\n Second number %d \nThird number %d\n",a,b,c); */

Output : 

Enter three values 
40
First number : 40
 Second number 20 
Third number 30

Enter three values 
40&50&60
First number : 40
 Second number 20 
Third number 30

Enter three values 
ABC-5-90
First number : 10
 Second number 20 
Third number 30

Enter three values 
40-50-60
First number : 40
 Second number 50 
Third number 60



/*int a,b;

int c,d,e,f;

printf ("Enter two digits \n");

scanf ("%d %d",&a,&b);

c = a + b;
d = b - a;
e = a * b;
f = b / a;

printf ("%d + %d = %d\n",a,b,c);
printf ("%d - %d = %d\n",b,a,d);
printf ("%d * %d = %d\n",a,b,e);
printf ("%d / %d = %d\n",b,a,f);
*/

Output : 
Enter two digits 
10
20
10 + 20 = 30
20 - 10 = 10
10 * 20 = 200
20 / 10 = 2


/*int a,b;

float c,d,e,f;

printf ("Enter two digits \n");

scanf ("%d %d",&a,&b);

c = a + b;
d = b - a;
e = a * b;
f = b / a;

printf ("%d + %d = %f\n",a,b,c);
printf ("%d - %d = %f\n",b,a,d);
printf ("%d * %d = %f\n",a,b,e);
printf ("%d / %d = %f\n",b,a,f);
*/

Enter two digits 
10
20
10 + 20 = 30.000000
20 - 10 = 10.000000
10 * 20 = 200.000000
20 / 10 = 2.000000


Enter two digits 

20
10
20 + 10 = 30.000000
10 - 20 = -10.000000
20 * 10 = 200.000000
10 / 20 = 0.000000

Enter two digits 
20
10
20 + 10.000000 = 30.000000
10.000000 - 20 = -10.000000
20 * 10.000000 = 200.000000
10.000000 / 20 = 0.500000


/* int h;
float c,d,e,f,g;

printf ("Enter two digits \n");

scanf ("%d %d",&a,&b);

c = a + b;
d = b - a;
e = a * b;
f = b / a;
g = b % a;


printf ("%d + %d = %f\n",a,b,c);
printf ("%d - %d = %f\n",b,a,d);
printf ("%d * %d = %f\n",a,b,e);
printf ("%d / %d = %f\n",b,a,f);
printf ("%d MOD %d = %f\n",b,a,g); */


Enter two digits 
20
10
20 + 10 = 30.000000
10 - 20 = -10.000000
20 * 10 = 200.000000
10 / 20 = 0.000000
10 MOD 20 = 10.000000



/*
char z = 'E';
int a,b;
float c;

printf ("Enter two digits \n");

scanf ("%d %d",&a,&b);

c = z / b;

printf ("%d / %d = %f \n",z,b,c);
*/

Enter two digits 
20
10
69 / 10 = 6.000000 


/*
int a = 10;
int b=a;

printf ("%d : Value after assigning value of a\n",b);

b = ++a;

printf ("%d : Value after Post Increment\n",b);
*/

Output :
10 : Value after assigning value of a
11 : Value after Post Increment

/*
int a = 10;
int b=a;

printf ("%d : Value after assigning value of a\n",b);

b = a++;

printf ("%d : Value after Post Incrementing\n",b);
*/
Output:
10 : Value after assigning value of a
10 : Value after Post Incrementing


/* int a = 10,b=20,c=30;

int d;

d = ++a + ++b + c++ * a;

printf ("%d \n",d);
*/
Output : 362 

}

Session Three

/*
 * Session_3.c
 *
 *  Created on: Nov 12, 2016
 *      Author: Admin
 */

#include<stdio.h>
void main ()
{
setbuf(stdout, NULL);
//Output for all below sample programmes have been explained in class.
   /*  Session 3 : Program 1
int a;

setbuf(stdout, NULL);

printf("Enter A number \n");

scanf ("%d",&a);

printf ("Entered number is : %d \n",a);

Output :

Enter A number
10
Entered number is : 10

Session 3 : Program 2
int a,b,c;

printf("Enter Three different numbers \n");

scanf ("%d %d %d",&a,&b,&b);

printf ("Entered numbers are %d , %d , %d \n",a,b,c);

Enter Three different numbers
10
20
30
Entered numbers are 10 , 30 , 4203625


Session 3 : Program 3

int a,b,c;

printf("Enter Three different numbers \n");

scanf ("%d %d %d",&a,&a,&a);

printf ("Entered numbers are %d , %d , %d \n",a,b,c);

Enter Three different numbers
10
20
30
Entered numbers are 30 , 4203625 , 2293400

Session 3 : Program 4

int a;

float b;

printf ("Enter an integer and float number respectively \n");

scanf ("%d %f",&a,&b);

printf ("Entered integer number : %d \n Entered floating point number: %f\n",a,b);

Output :
Enter an integer and float number respectively
10
34.567
Entered integer number : 10
Entered floating point number: 34.567001

Session 3 : Program 5
int a;

float b;

printf ("Enter an integer and float number respectively \n");

scanf ("%d %d",&b,&a);

printf ("Entered integer number : %d \n Entered floating point number: %f\n",a,b);

Output :
Enter an integer and float number respectively
234
456.78965
Entered integer number : 456
Entered floating point number: 0.000000


int a, b, c;

printf ("Enter 3 integers  \n");

scanf ("%2d %2d %3d",&a,&b,&c);

printf ("Entered 1st number : %d, Entered 2nd number %d, Entered 3rd number %d",a,b,c);

Output :

Enter 3 integers
1 245 789
Entered 1st number : 1, Entered 2nd number 24, Entered 3rd number 5

*/
}

Monday, 7 November 2016

Session 2 : Program 2

Sample Program 2 :
/*
* Session_Two_Data_Types.c
*
* Created on: Nov 6, 2016
* Author: Admin
*/
#include<stdio.h>
void main()
{
setbuf(stdout, NULL);
char alphabet = 'a';
int m1 =100;
int m2 = 90;
float num1 = 1612345678.12345678;
float num2 = 13.34568789;
/* Implicit conversion happens only between int and char without any assignment */
printf ("Value of variable alphabet as char %c \n",alphabet);
printf ("Value of variable alphabet as integer %d \n",alphabet);
printf ("Value of variable alphabet as hexadecimal %x \n",alphabet);
printf ("Value of variable alphabet as octa decimal %o \n",alphabet);
/*In correct types */
printf ("In correct formatting types for char\n");
printf ("Value of variable alphabet as float %f \n",alphabet);
printf ("Value of variable alphabet as double %lf \n\n\n",alphabet);
printf ("Marks 1 = %d , Marks 2 = %2d \n",m1,m2);
/*In correct types */
printf ("In correct formatting types for Decimal\n");
printf ("Marks 1 as char = %c , Marks 2 as char = %c \n",m1,m2);
printf ("Marks 1 as float = %f , Marks 2 as double = %lf \n\n\n\n",m1,m2);
printf ("Number 1 = %f , Number 2 = %f \n",num1,num2);
printf ("Number 1 = %6.3f , Number 2 = %5.1f \n",num1,num2);
printf ("Number 1 = %E , Number 2 = %5.1f \n",num1,num2);
/*In correct types */
printf ("In correct formatting types for Decimal \n");
printf ("Number 1 = %c , Number 2 = %d \n",num1,num2);
printf ("Number 1 = %lf , Number 2 = %x\n",num1,num2);
printf ("Number 1 = %X , Number 2 = %u \n",num1,num2);
}
Output :
Value of variable alphabet as char a
Value of variable alphabet as integer 97
Value of variable alphabet as hexadecimal 61
Value of variable alphabet as octa decimal 141
In correct formatting types for char
Value of variable alphabet as float 0.000000
Value of variable alphabet as double 0.000000
Marks 1 = 100 , Marks 2 = 90
In correct formatting types for Decimal
Marks 1 as char = d , Marks 2 as char = Z
Marks 1 as float = 0.000000 , Marks 2 as double = 0.000000
Number 1 = 1612345728.000000 , Number 2 = 13.345688
Number 1 = 1612345728.000 , Number 2 = 13.3
Number 1 = 1.612346E+009 , Number 2 = 13.3
In correct formatting types for Decimal
Number 1 =

Session 2 : Program 1

Sample Program 1 :
/*
* Session_Two_Data_Types.c
*
* Created on: Nov 6, 2016
* Author: Admin
*/
#include<stdio.h>
void main()
{
setbuf(stdout, NULL);
char alphabet = 'a';
int m1 =100;
int m2 = 90;
float num1 = 1612345678.12345678;
float num2 = 13.34568789;
/* Implicit conversion happens only between int and char without any assignment */
printf ("Value of variable alphabet as char %c",alphabet);
printf ("Value of variable alphabet as integer %d",alphabet);
printf ("Value of variable alphabet as hexadecimal %x \n",alphabet);
printf ("Value of variable alphabet as octa decimal %x \n",alphabet);
printf ("Marks 1 = %d , Marks 2 = %d \n",m1,m2);

printf ("Number 1 = %f , Number 2 = %f \n",num1,num2);
printf ("Number 1 = %6.3f , Number 2 = %5.1f \n",num1,num2);
/* In above statement 6 specifies how many digits we need to print totally, including "."
But if our value increases 6 digits, then the entire value withh be printed ignoring 6 in formatting string.
3 here is precision, this is to specify number of decimal degits we need to print.
Detailed discussion has been done in class */
printf ("Number 1 = %E , Number 2 = %5.1f",num1,num2);

}
Output :
Value of variable alphabet as char a
Value of variable alphabet as integer 97
Value of variable alphabet as hexadecimal 61
Value of variable alphabet as octa decimal 61
Marks 1 = 100 , Marks 2 = 90
Number 1 = 1612345728.000000 , Number 2 = 13.345688
Number 1 = 1612345728.000 , Number 2 = 13.3
Number 1 = 1.612346E+009 , Number 2 = 13.3

Session 2 : Briefing

Session Two :
Data Types
Integer ( Decimal, Octal, Hexademimal ) {Signed , Unsigned}
Floating
Double
Character
Range of the data types depends on machine. So, we have written a program to find the range which is shared at later stage.
Examples for different data types are discussed in class.
Variables :
How to define a variable?
datatype v1,v2,v3..;
Initialisation :
datatype variable_name = data;
Here, variable name is an alias to backend memory, data is stored in that memory location.
Formatted input output functions /*Unformatted functions are dealt in previous class */
Unformatted i/o function:
getchar() : Reads character from keyboard , waits for user to type character and then enter keyboard
getch() : Reads a character from keyboard and doesnt wait for enter key.
getche() : Reads a character from keyboard and doesnot wait for user to type enter key. Character enter will be echoed.
gets() : Reads a string from keyboard and waits for user to type ENTER key.
putchar() / putch() : To echo character on screen
puts() : Echos string on screen.
Formatted function:
Data Types with Format specifier.
int :
%d --> Data into decimal signed integer
%u --> Data into decimal unsigned integer
%o --> Data into octal integer
%x / %X --> Data into Hexademimal integer
%h --> Data into short integer

float :
%f --> Data into floating point value
%e / %E --> Data into floating point exponential value
double :
%lf / %Lf : Data into LONG floating point value
char :
%c --> Converts data into character
%s --> Converts data into string

Friday, 4 November 2016

Basics of C "Alphabets"

Basics of C "Alphabets"
Topics covered for the day :
Intorduction on LikeCProgramming tutours
Importance of C porgamming
Introduction to C Programming
Alphabets of C
Tokens
Identifiers
Constant (Integer Only)
Few simple programming snippets
Programming snippets
/* 1. Happy path : Successful execution of program */
void main()
{
puts ("Welcome to our C programming classes");
}

/* 2. Pre-processor usage : #include <stdio.h> */
#include <stdio.h>
void main()
{
printf ("Welcome to our C programming classes");
}

/* 3. Printf without Preprocessor
Output : Compilation error*/
void main()
{
printf ("Welcome to our C programming classes");
}

/* 4. Importance of " ; " */
/* Output : Compilation Error */
#include <stdio.h>
void main()
{
printf ("Welcome to our C programming classes")
}

/* 5. Chnage in return type */
/* Output : Successful execution of program */
#include <stdio.h>
int main()
{
printf ("Welcome to our C programming classes");
}

/* 5. Difference in return type */
/* Output : Successful execution of program, BUT with warnings */
#include <stdio.h>
void main()
{
printf ("Welcome to our C programming classes");
return 10;
}

/* 6. White spaces after double quotes */
/* Output : Successful execution of program */
#include <stdio.h>
void main()
{
printf ("Welcome to our C programming classes"
);
}

/* 7. White spaces with in double quotes */
/* Output : Compilation error */
#include <stdio.h>
void main()
{
printf ("Welcome to our C
programming classes");
}


/* 8. White spaces with in double quotes */
/* Output : Compilation error */
#include <stdio.h>
void main()
{
printf ("Welcome to our C
programming classes");
}