Showing posts with label Programmer. Show all posts
Showing posts with label Programmer. Show all posts

Monday, 25 June 2012

Programmer | C | C++ | C Programmer | c# | Software | It Programmer

You will be good programmer after learning these tutorials. Now start from first program and learn all programs. At the end you will solve some assignments, these assignments will increase your programming skills.


Q.1  Write a program that reads user’s age and prints CHILD if age < 18, ADULT if
18 =< age < 35, SENIOR if age >= 35.
Solution:-


#include"stdio.h"
int a;
void main()
{
clrscr();
printf("Enter your age ");
scanf("%d",&a);
if (a>=35)
printf("\nSENIOR");
else if (a>=18)
printf("\nADULT");
else
printf("\nCHILD");
getch();
}
------------------------------------------------------------------------


Q.2  Write segment of program that reads a grade A,B,C,D or F and
then prints “Excellent”, “Good”, “Fair”, “Poor” or “Failure”
depending on grade. Use multiple-if statement.
Solution :-


#include"stdio.h"
char ip;
void main()
{
clrscr();
printf("Enter your grade ");
ip=getche();
if(ip=='A' || ip=='a')
printf("\nExcellent");
else if(ip=='B' || ip=='b')
printf("\nGood");
else if(ip=='C' || ip=='c')
printf("\nFair");
else if(ip=='D'||ip=='d')
printf("\nPoor");
else if(ip=='F'||ip=='f')
printf("\nFailure");
else
printf("\nInvalid Input");
getch();
}
--------------------------------------------------------------------

Q.3 Write a program that finds maximum and minimum
of  three numbers using multiple-if or nested-if statement.*/
Solution :-


#include"stdio.h"
int a,b,c,max,min;
void main()
{
clrscr();
printf("\nEnter first number ");
scanf("%d",&a);
printf("\nEnter second number ");
scanf("%d",&b);
printf("\nEnter third number ");
scanf("%d",&c);
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else
max=c;
if(a<b && a<c)
min=a;
else if(b<a && b<c)
min=b;
else
min=c;
printf("\nMaximum is %d \nMinimum is %d",max,min);
getch();
}

---------------------------------------------------------------------
Q.4  01/01/1900, the day was Monday. If any year is input
through keyboard, write a program to find out day on 1st
Jan of that year.

Solution :-
#include"stdio.h"


unsigned long int  y/*yearenter by user*/,d/*interval of years from 1900*/,r;
void main()
{
clrscr();
printf("Enter a year ");
scanf("%d",&y);
d=y-1900;
if(y<1900)
d=1900-y;
r=((d*365)+(d/4))%7;
printf("\n");
switch (r)
{
case 0:
printf("Monday");
break;
case 1:
printf("Tuesday");
break;
case 2:
printf("Wednesday");
break;
case 3:
printf("Thursday");
break;
case 4:
printf("Friday");
break;
case 5:
printf("Saturday");
break;
case 6:
printf("Sunday");
break;
default:
printf("Invalid Input");
}
getch();
}

---------------------------------------------------------------------
Q.5  Read two +ve integer numbers N1 and N2, and then test
whether the larger number is exactly divisible by the smaller one.
In the process, check that the input numbers are valid
(N1 and N2>0) and then check which of the number is greater.

Solution :-

#include"stdio.h"
int l,s,v;
void main()
{
clrscr();
printf("Enter first number ");
scanf("%d",&l);
printf("\nEnter second number ");
scanf("%d",&s);
if(s>l)
{v=s;
s=l;
l=v;}
if(l>=0 && s>=0)
{ if(l%s==0)
printf("\nInput numbers are valid \n The larger number is exactly divisible by the smaller ");
else
printf("\nInput numbers are valid but larger number is not exactly divisible by the smaller ");
}
else
printf("\nInput numbers are Invalid ");
getch();
}


---------------------------------------------------------------------
Q.6 Write a program that reads an integer number from
the user (within range 1-100). Then check whether the
number is greater than, less than or equal to 50.

Solution :-


#include"stdio.h"
int n;
void main()
{
clrscr();
printf("Enter anumber (within range 1-100) ");
scanf("%d",&n);
if(n>=1 && n<=100)
{ if(n<50)
printf("%d is less than 50",n);
else if(n>50)
printf("%d is greater than 50",n);
else
printf("%d is equal to 50",n); }
else
printf("%d is out of range ",n);
getch();
}

---------------------------------------------------------------------
Q.7 Write a program that takes the lengths of the two legs of
a right triangle as input and calculates area and hypotenuse.

Solution :-

#include"stdio.h"
#include"math.h"
float p,b,h,a;
void main()
{
clrscr();
printf("Enter perpendicular of triangle ");
scanf("%f",&p);
printf("\nEnter base \tof triangle ");
scanf("%f",&b);
h=sqrt(p*p+b*b);
a=(0.5)*p*b;
printf(" \nHypotenuse is %f",h);
printf(" \nArea is %f",a);
getch();
}


---------------------------------------------------------------------
Q.8 A pharmaceutical company pays 10% house rent of basic
salary & 90% daily allowance of basic salary to its employees if the
basic pay of the employee is less than 1500. The company pays
20% house rent & 95% daily allowance of basic salary if the basic
pay of the employee is greater than or equal to1500. Write an algorithm
that takes basic salary of an employee and calculate & print his gross
salary.

Solution :-

#include"stdio.h"
float s,gs;
void main()
{
clrscr();
printf("Enter employee basic salary ");
scanf("%f",&s);
gs=(s<1500)?0.1*s+s*0.9+s:0.2*s+0.95*s+s;/*Turnary operator max=(x>y)?x:y;*/
printf("\nGross Salary of Employee is %f",gs);
getch();
}


---------------------------------------------------------------------

Q.9  Write a program that creates a simple calculator. It reads two float numbers N1, N2
and a character CH (+,-,*,/), then perform calculation depending upon the type of
character entered by user and display result in format…N1 op N2 = result.

Solution :-

#include"stdio.h"
float n,m,r;
char op;
void main()
{
clrscr();
printf("Enter first number ");
scanf("%f",&n);
printf("\nEnter operator ");
op=getche();
printf("\nEnter second number ");
scanf("%f",&m);
switch (op)
{
case'+':
r=n+m;
break;
case'-':
r=n-m;
break;
case'*':
r=n*m;
break;
case'/':
r=n/m;
break;
default:
printf("Invalid Input");
}
if(op=='+'||op=='-'||op=='*'||op=='/' )
{ printf("\n%f%c%f=%f",n,op,m,r); }
getch();
}

---------------------------------------------------------------------
Q. 10  Write a complete program that calculates roots of
quadratic equation. Implement all three cases.
(roots are equal/roots are real/roots are imaginary).

Solution :-

#include"stdio.h"
int r,a,b,c;
void main()
{
clrscr();
printf("Enter first Coefficient ");
scanf("%d",&a);
printf("\nEnter second Coefficient ");
scanf("%d",&b);
printf("\nEnter third Coefficient ");
scanf("%d",&c);
r=b*b-4*a*c;
if(r>0)
printf("Roots are Real");
else if(r==0)
printf("Roots are Equal");
else if(r<0)
printf("Roots are Imaginary");
else
printf("Invalid Inputs");
getch();
}

---------------------------------------------------------------------
Q.11

Solution :-

---------------------------------------------------------------------
Q.12

Solution :-

---------------------------------------------------------------------
Q.13

Solution :-

---------------------------------------------------------------------
Q.14

Solution :-

---------------------------------------------------------------------
Q.15

Solution :-

---------------------------------------------------------------------