-->

Facebook

Jasper Roberts - Blog

Tuesday, March 31, 2015

Write a C Program to Add, subtract and multiply two nos. using switch statement.



PRACTICAL-SET-4
3.  Add, subtract and multiply two nos. using switch statement.


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

void main()
{
int num1,num2, choice;
clrscr();

printf("Enter the value of number1 : ");
scanf("%d",&num1);

printf("Enter the value of number2 : ");
scanf("%d",&num2);


printf("\n 1. Addition, ");
printf("\n 2. Substraction,");
printf("\n 3. Multiplication,  ");
printf("\n 4. Division.");

printf("\n Enter Your Choice:");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("%d + %d = %d",num1, num2, num1+num2);
break;

case 2:
printf("%d - %d = %d",num1, num2, num1-num2);
break;

case 3:
printf("%d * %d = %d",num1, num2, num1*num2);
break;
case 4:
printf("%d / %d = %d",num1, num2, num1/num2);
break;

default:
printf("Please enter the correct choise!!");
}
getch();

}

OUTPUT:
Enter the value of number1 : 10
Enter the value of number2 : 10
 1. Addition,
 2. Substraction,
 3. Multiplication,
 4. Division.

Enter Your Choice:1
10 + 10 = 20

Write a c program to reverse the digit.

PRACTICAL-SET-
2.  Write a prograto reverse the digit.


#include<stdio.h>
#include<conio.h>

void main()
{
    int num,r,reverse=0;
    clrscr();

    printf("Enter the number: ");
    scanf("%d",&num);

    while(num)
{
         r=num%10;
         reverse=reverse*10+r;
         num=num/10;
    }

    printf("Reverse of a given number is = %d",reverse);
getch();
}

OUTPUT:
Enter the number:  1234
Reverse of a given number is = 4321

Saturday, March 21, 2015

Chapter 3 - Control structure in C:


Simple statements,                              | CLICK HERE
Decision making statements,              | CLICK HERE
Looping statements,                            | CLICK HERE
Nesting of control structures,              | CLICK HERE 
break and continue ,                            | CLICK HERE
goto statement.                                   | CLICK HERE

break and continue

break:
-In C programming language, break is used in terminating the loop immediately after it is encountered.
-The break statement is used with conditional if statement.
-Generally break statement is used in switch case statement at the end of the each and every case.

example:
              break;


continue:
-It is sometimes desirable to skip some statements inside the loop of a program.
-At that time or situation, continue is used.

example:
             continue;

Control Structure loops in C Language

while loop                       |
do...while loop                |   CLICK HERE
for loop                           | 

Decision Making Statements

1. Simple if statement   CLICK HERE
2. if...else statement     CLICK HERE
3. switch case statement    CLICK HERE
4. ladder if else statement (multiple if...else if statement)      CLICK HERE

Thursday, March 12, 2015

Write a C++ Program to demonstrate character data type.

#include<iostream.h>
//using namespace std;
class Person
{
char name[30];
int age;
public:
void get_data(void);
void display();
};
void Person::get_data(void)
{
cout<<"Enter the name : ";
cin>>name;
cout<<"\nEnter the age : ";
cin>>age;
};
void Person::display(void)
{
cout<<"\nName : "<<name;
cout<<"\nAge : "<<age;
};
void main()
{
Person p;
p.get_data();
p.display();
}

Write a C++ Program to calculate average and sum.

#include<iostream.h>
//using namespace std;
void main()
{
float x,y,s,a;
cout<<"Enter the number : "<<"\n";
cin>>x>>y;
s=x+y;
a=s/2;
cout<<"\nSum = "<<s;
cout<<"\nAvg = "<<a;
}

Write a C program to convert km to meter, inch, cm and feet.

#include
#include

void main(){
float km,m,feet,inch,cm; 
printf("Enter the distance between two cities(in km) - ");
scanf("%f",&km);
m = km*1000; //since 1km = 1000m
feet= km*3280.84; //since 1km=3280.84feet
inch=km*39370.1; //since 1 km=39370.1inches
cm=km*100000; //since 1km = 100000cm
printf("\nDistance in kilometres = %f ",km);
printf("\nDistance in metres = %f ",m);
printf("\nDistance in feet = %f ",feet);
printf("\nDistance in inches = %f ",inch);
printf("\nDistance in centimetres = %f ",cm);
getch();
}

go to statement in c programming language.

- In c programming language, if statement, if...else statement, switch statements provides conditional jumps.
- A goto statement in C programming language provides an unconditional jump from the goto to a labeled statement in the same function.
- Use of goto statement is highly discouraged in c programming language.
- Because it makes difficult to trace the control flow of a program making the program hard to understand and debug.

- Syntax:
goto label;
.
.
.
label: statement;

-Example:

#include<stdio.h>
#include<conio.h>

void main()
{

  int number = 10;

  A:
       do
       {
          if( number == 15)
      {
         number = number + 1;
         goto A;
      }
      printf("\n value of number is: %d",number);
      number++;
   
   }while( number < 20 );

   getch();
}

OUTPUT:
value of number is:11
value of number is:12
value of number is:13
value of number is:14
value of number is:15
value of number is:16
value of number is:17
value of number is:18
value of number is:19

Write a C Program to reverse the given number.

#include<conio.h>
#include<stdio.h>

void main()
{
  int number,rem;
  int reverse=0;
  printf("Enter an integer number: ");
  scanf("%d", &number);
  while(number!=0)
  {
     rem=number%10;
     reverse=reverse*10+rem;
     number=number/10;
  }
  printf("Reversed Number = %d",reverse);
  getch();
}

OUTPUT:
Enter an integer number: 123
Reversed Number = 321

Wednesday, March 11, 2015

Write a C++ Program to convert temperature into Fahrenheit.

#include<iostream.h>
//using namespace std;
class Temp
{
float c,f;
public:
void get_temp(void);
void convert(void);
void display(void);
};
void Temp::get_temp(void)
{
cout<<"\nEnter the temparature : ";
cin>>c;
};
void Temp::convert(void)
{
f=(c-32)/9.8;
};
void Temp::display(void)
{
cout<<"Temparature in F = "<<f;
};
void main()
{
Temp t;
t.get_temp();
t.convert();
t.display();
}


RELATED TOPICS
Write a C++ Program to demonstrate class.
Write a C++ Program to demonstrate scope resolution operator.

Write a C++ Program to demonstrate class.

#include<iostream.h>
//using namespace std;
class Abc
{
int a,b,c,x;
public:
void get_data(void);
void count(void);
void display(void);
};
void Abc::get_data(void)
{
cout<<"\nEnter the value of a = ";
cin>>a;
cout<<"\nEnter the value of b = ";
cin>>b;
cout<<"\nEnter the value of c = ";
cin>>c;
};
void Abc::count(void)
{
x=a/(b-c);
};
void Abc::display(void)
{
cout<<"\n x = "<<x;
};
void main()
{
Abc a;
a.get_data();
a.count();
a.display();
}

RELATED TOPICS
Write a C++ Program to convert temperature into Fahrenheit.
Write a C++ Program to demonstrate scope resolution operator.

Write a C++ Program to demonstrate scope resolution operator.

#include<iostream.h>
//using namespace std;
int m=10;
int main()
{
int m=20;
{
int k=m;
int m=30;
cout<<"\nWe are in iner block"<<"\n";
cout<<"\nk = "<<k;
cout<<"\nm = "<<::m;
}
cout<<"We are in outer block"<<"\n";
cout<<"\nm = "<<m;
return 0;
}

RELATED TOPICS
Write a C++ Program to convert temperature into Fahrenheit.
Write a C++ Program to demonstrate class.

Tuesday, March 10, 2015

Assignment - 2 CPU(2110003)

1. Write a short note on data types. 
2. What is constant? Explain numerical constant and non-numerical constant. 
3. Explain C operators in details. 
4. What is type conversion? Explain it. 
5. Explain features of c language.

Click Here to Download
RELATED TOPICS
Assignment-1
Assignment-3
Assignment-4
Assignment-5
Assignment-6
Assignment-7
Assignment-8
Assignment-9








Assignment-1 CPU(2110003)

1. Draw the block diagram of computer system. Explain types of software.

2. Explain middle level language, high level language and low level language.

3. What is flow chart? Give the symbols used to draw flow chart.

4. What is flow chart? Draw a flow chart to find out the largest number among three numbers.

5. What is an algorithm? Write an algorithm to find out smallest number among three numbers.

Click Here to Download
RELATED TOPICS
Assignment-2
Assignment-2
Assignment-3
Assignment-4
Assignment-5
Assignment-6
Assignment-7
Assignment-8
Assignment-9

Friday, March 6, 2015

Happy Holi....

Hello Everyone
Wish You Happy Holi....
HAPPY HOLI C FOR ALL 2015
HAPPY HOLI

Monday, March 2, 2015

A C Program to represent Secant Method.

#include<stdio.h>
#include<conio.h>
double f(double x)
{
return (2*x*x*x-3*x*x+5*x-6);
};
void main()
{
int iter,ctr=1;
double x0,x1,r;
clrscr();
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
while(ctr<=iter)
{
r=((x0*f(x1))-(x1*f(x0)))/(f(x1)-f(x0));
printf("\nAfter %d itteration root is = %lf",ctr,r);
x0=x1;
x1=r;
ctr++;
};
printf("\n\nThe approximate root is = %lf",r);
getch();
}


RELATED TOPICS
A C Program to represent N-R Method.
A C Program to represent the Bisection Method.

A C Program to represent N-R Method.

#include<conio.h>
#include<stdio.h>
double f(double x)
{
return (x*x*x+2*x*x+10*x-20);
};
double df(double x)
{
return (3*x*x+4*x+10);
};
void main()
{
int iter,ctr=1;
double x0,x1,l1,l2,r,x2;
clrscr();
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
x2=((x0+x1)/2);
while(ctr<=iter)
{
r=x2-(f(x2)/df(x2));
printf("\nAfter %d itteration root is = %.4lf",ctr,r);
x2=r;
ctr++;
}
printf("\n\nThe approximate root is = %.4lf",r);
getch();
}
RELATED TOPICS
A C Program to represent the Bisection Method.
A C Program to represent Secant Method.

A C Program to represent the Bisection Method.

#include<stdio.h>
#include<conio.h>
double F(double x)
{
return(x*x*x-x-1);
};
void main()
{
int iter,ctr=1;
double x0,x1,l1,l2,r;
clrscr();
printf("\nEquation is :\n\n\tx^3-x-1");
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
while(ctr<=iter)
{
r=(x0+x1)/2;
printf("\nAfter %d  itteration root is : %lf",ctr,r);
l1=F(r);
printf("\t%lf",l1);
l2=F(x0);
if(l1*l2<0)
x1=r;
else
x0=r;
ctr++;
}
printf("\n\nThe approximate root is : %lf",r);
getch();
}
RELATED TOPICS
A C Program to represent N-R Method.
A C Program to represent Secant Method.

if...else if ladder(multiple if else)

- In c language, if else statement provides two way decision only.

- In some case, we need to check multiple choice.

- At that time, we can use if...else if ladder(multiple if else statement).

- if...else if ladder provides multi-way decision. There may be more than one condition in Program at that time use if..else if ladder.

syntax:
     if(condition-1)
          statement-1;

     else if(condition-2)
          statement-2;
     else if(condition-3)
          statement-3;
          .
          .
          .
     else if(condition-n)
          statement-n;
     else
          statement;

- In if..else if ladder, the condition-1 is true than it will execute the statement-1.

- If the condition-2 is true than it will execute the statement-2. Same way it will check
All the condition.

Flow Chart:
multiple if else statement
multiple if else


Example: A c program to check the given year is leap year or not.

#include<stdio.h>
#include<conio.h>

void main()
{
  int year;

  printf("Enter a year:");
  scanf("%d", &year);

  if(year%4 == 0)
      printf("\n This is a leap year.", year);
  else if (year%400 == 0)
      printf("\n This is a leap year.", year);

  else if(year%100 == 0)
      printf("\n This is not a leap year.", year);
  else
      printf("\n This is not a leap year.", year); 

  getch();
}

OUTPUT:
Enter a year: 2011
This is not a leap year.


if...else statement in C language.

 - In C programming language, c provides if...else statement to take two-way decision.
 - If the condition is true than it will execute the statement(s)-1, if the condition is false than it will execute the    statement(s)-2.
 - In C, Simple if statement provides only one way decision but if...else statement provides two-way                 decision.
 - If the statements are more than one than it will be written in { and } braces.

Syntax:
            if(condition)
                      statement(s)-1;
            else
                      statement(s)-2;

Example:
#include<conio.h>
#include<stdio.h>

Simple if statement.

-In C programming language, c provides if statement to take one way decision.

-If the condition is true than it will execute the statement(s) otherwise it will not execute the statement(s).

Syntax:
          if(condition)
                 statement(s);
if statement theory
simple if statement