Look out for the Programming in different languages (C,C++,SQL,PL\SQL,SHELL SCRIPT etc).
C Programming : Assignment 2
Assignment 2
Q1: Write a c program to find the biggest of given three
numbers.
#include<stdio.h>
#include<conio.h>
void main(){
int a,b,c;
clrscr();
printf("\nEnter
value for a:");
scanf("%d",&a);
printf("\nEnter
value for b:");
scanf("%d",&b);
printf("\nEnter
value for c:");
scanf("%d",&c);
if(a>b
&& a>c)
{
printf("\nThe
Greatest Number Is a:%d",a);
}
else
{
if(b>a
&& b>c)
printf("\nThe
Greatest Number Is b:%d",b);
else
printf("\nThe
Greatest Number Is c:%d",c);
}
getch();
}
Q2: Write a c program to find the value of y using
Y(x,n)=1+(x*x)
when n=1
=1+x/n when n=2
=1+2x when n=3
=1+nx when n>3 or n<1
Note: Do the program using if else condition.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,n,Y;
clrscr();
printf("\n\t\tEnter
the value for n(BUT NOT MORE THAN 3):");
scanf("%d",&n);
printf("\n\t\t
Set value of x=");
scanf("%d",&x);
if(n==1)
{
Y=1+(x*x);
printf("Y=%d",Y);
}
else
if(n==2)
{
Y=1+x/n;
printf("Y=%d",Y);
}
else
if(n==3)
{
Y=1+(2*x);
printf("Y=%d",Y);
}
else
if(n>3
|| n<1)
{
Y=1+(n*x);
printf("Y=%d",Y);
}
getch();
}
Q3: Q2: Write a c program to find the value of y using
Y(x,n)=1+(x*x)
when n=1
=1+x/n when n=2
=1+2x when n=3
=1+nx when n>3 or n<1
Note: Do the program using switch case condition.
#include<stdio.h>
#include<conio.h>
void main()
{
int y,x,n;
clrscr();
printf("\n\t\tEnter
The Value For n(not more than 3):");
scanf("%d",&n);
printf("\n\t\tEnter
The Value For x: ");
scanf("%d",&x);
switch(n)
{
case
1:
y=1+(x*x);
printf("\t\tY=%d",y);
break;
case
2:
y=1+(x/n);
printf("\t\tY=%d",y);
break;
case
3:
y=1+(2*x);
printf("\t\tY=%d",y);
break;
default:
y=1+(n*x);
printf("\t\tY=%d",y);
break;
}
getch();
}
Q4: Write a program to find the roots of a quadratic
equation.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,p;
double x;
clrscr();
printf("\n\t\tEnter
value of a:\n\t\tEnter value of b:\n\t\tEnter the value of c:");
scanf("%d,%d,%d",&a,&b,&c);
x=-b+sqrt(((b*b)-4*a*c)/2);
x=-b-sqrt(((b*b)-4*a*c)/2);
p=(b*b)-4*a*c;
switch(p)
{
case
:
printf("\n\t\t
The Roots Are Real And Unequal...");
break;
case
'p==0':
printf("\n\t\t
The Roots Are Real And Equal...");
break;
case
'p<0':
printf("\n\t\t
The Roots Are imaginary...");
break;
}
getch();
}
Q5: Write a program for Electric bill distribution by using
if else condition or switch case.
#include<stdio.h>
#include<conio.h>
void main()
{
int unit,rs;
clrscr();
printf("\t\tElectric
Bill\n");
printf("\t\tEnter
the unit for any particular user:");
scanf("%d",&unit);
if(unit<=200)
{
rs=0.5
* unit;
printf("\t\tThe
amount to be paid:\n\t\tRs.%d/-",rs);
}
if(unit>200
&& unit<=400)
{
rs=100+(unit
* 0.65);
printf("\t\tThe
amount to be paid:\n\t\tRs.%d/-",rs);
}
if(unit>400
&& unit<=600)
{
rs=200+(0.80
* unit);
printf("\t\tThe
amount to be paid:\n\t\tRs.%d/-",rs);
}
if(unit>600)
{
rs=425+(1.25
* unit);
printf("\t\tThe
amount to be paid:\n\t\tRs.%d/-",rs);
}
getch();
}
Q6: Write a c program for grading system of the students.
#include<stdio.h>
#include<conio.h>
void main()
{
int marks,sci,maths,social,eng,hindi,total;
float avg;
clrscr();
printf("\t\tSTUDENT
GRADES\n");
printf("\nEnter
the marks:");
printf("\nFor
ENGLISH:");
scanf("%d",&eng);
printf("\nFor
HINDI:");
scanf("%d",&hindi);
printf("\nFor
SCIENCE:");
scanf("%d",&sci);
printf("\nFor
MATHEMATICS:");
scanf("%d",&maths);
printf("\nFor
SOCIAL SCIENCE:");
scanf("%d",&social);
total=eng+hindi+sci+maths+social;
avg=total/5;
printf("\n\tTOTAL
MARKS OBTAINED STUDENT: %d",total);
printf("\n\n\tAVERAGE
PERCENTAGE OBTAINED STUDENT: %f\n\n",avg);
if(avg>=90)
{
printf("\tGRADE:
O");
}
if(avg>=80
&& avg<90)
{
printf("\tGRADE:
E");
}
if(avg>=70
&& avg<80)
{
printf("\tGRADE:
A");
}
if(avg>=60
&& avg<70)
{
printf("\tGRADE:
B");
}
if(avg>=50
&& avg<60)
{
printf("\tGRADE:
C");
}
if(avg>=40
&& avg<50)
{
printf("\tGRADE:
D");
}
if(avg<40)
{
printf("\tGRADE:
F ");
}
printf("\nO:Outstanding\nE:Excellent\nA:Very
Good\nB:Good\nC:Average\nD:Just Passed\nF:Failed");
getch();
}
C Programming : Assignment 1
Q-1: Mr. Aggarwal is an employee of a Private Firm. His Basic salary is Rs. 5500/-(suppose) . Now the dearness allowance is 74% of his basic salary and house rent allowance is 15% of basic salary. Write a program to calculate his gross salary.
#include<stdio.h>
#include<conio.h>
void main()
{
float gs,da,bs,hr;
clrscr();
printf("\n\t\tENTER THE BASIC SALARY OF AN EMPLOYEE:");
scanf("%f",&bs);
da=(bs*74)/100;
hr=(bs*15)/100;
gs=bs+hr+da;
printf("\n\t\tTHE GROSS SALARY:%f",gs);
getch();
}
Q-2: The length and breadth of a rectangle and radius of a circle are input through key board. Write a program to calculate the area and perimeter of the rectangle and the area and the circumference of the circle.
#include<stdio.h>
#include<conio.h>
void main()
{
float len,bre,aor,aoc,por,coc,rad;
clrscr();
printf("\n\t\tENTER THE LENGTH OF THE RECTANLE:");
scanf("%f",&len);
printf("\n\t\tENTER THE BREADTH OF THE RECTANLE:");
scanf("%f",&bre);
printf("\n\t\tENTER THE RADIUS OF THE CIRCLE:");
scanf("%f",&rad);
aor=len*bre;
por=2*(len+bre);
aoc=3.14*rad*rad;
coc=3.14*2*rad;
printf("\n\t\tTHE AREA OF RECTANGLE:%f",aor);
printf("\n\n\t\tTHE PERIMETER OF RECTANGLE:%f",por);
printf("\n\n\t\tTHE AREA OF CIRCLE:%f",aoc);
printf("\n\n\t\tTHE CIRCUMFERENCE OF CIRCLE:%f",coc);
getch();
}
Q-3: Temperatures of a city in Fahrenheit degree are input through a keyboard. Write a prgram to convert the temperature into centigrade degrees.
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
clrscr();
printf("\n\t\tENTER THE TEMPRATURE IN FARENHEIT:");
scanf("%f",&f);
c=5*(f-32)/9;
printf("\n\t\tTHE TEMPRATURE IS IN CELSIUS:%f",c);
getch();
}
Q-4-a: Write a program to swap two numbers by using third variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("\n\t\tENTER ANY NUMBER FOR a:");
scanf("%d",&a);
printf("\n\t\tENTER ANY NUMBER FOR b:");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("\n\t\tTHE SWAPPING OF a=%d AND b=%d",a,b);
getch();
}
Q-4-a: Write a program to swap two numbers without using third variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n\t\tENTER ANY NUMBER FOR a:");
scanf("%d",&a);
printf("\n\t\tENTER ANY NUMBER FOR b:");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n\t\tTHE SWAPPING OF a=%d AND b=%d",a,b);
getch();
}
Q-5: Write a program to find area of a triangle: Area of triangle = sqrt[s(s-a)(s-b)(s-c)] where a,b, and c are three sides of the triangle and s=a+b+c/2.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double s,a,b,c,aot;
clrscr();
printf("### Area Of Triangle ###\n");
printf("\nENTER THE VALUE FOR a:");
scanf("%lf",&a);
printf("\nENTER THE VALUE FOR b:");
scanf("%lf",&b);
printf("\nENTER THE VALUE FOR c:");
scanf("%lf",&c);
s=(a+b+c)/2;
printf("\nS=%lf",s);
aot=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nAREA OF TRIANGLE:%lf",aot);
getch();
}
Q-6: Write a program to calculate and print electricity bill for consumers, given the following information: service number, previous meter reading, and current reading.
#include<stdio.h>
#include<conio.h>
void main()
{
int pre,c,sn;
float bill_amt,pre_amt,unit;
clrscr();
printf("\t\tWelcome To Kolkata Electricity Board\n");
printf("\n\n ENTER SERVICE NUMBER:");
scanf("%d",sn);
printf("\nENTER THE PREVIOUS MONTH READING UNIT USED:");
scanf("%d",&pre);
printf("\nENTER THE CURRENT MONTH READING UNIT USED:");
scanf("%d",&c);
pre_amt=pre*2.5;
bill_amt=c*2.5;
printf("\nCustomer With SERVICE NUMBER:%d",sn);
printf("\n\t\tCustomer's Previous Bill Amount:%f",pre_amt);
printf("\n\t\tCustomer's Current Bill Amount:%f",bill_amt);
getch();
}
Program to enter the sale value and print the agent's commission
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
long int svalue;
float commission;
cout << "Enter the total sale value : " << endl;
cin>>svalue;
if(svalue<=10000)
{
commission=svalue*5/100;
cout << "For a total sale value of $" << svalue << ", ";
cout << "the agent's commission is $" << commission;
}
else if(svalue<=25000)
{
commission=svalue*10/100;
cout << "For a total sale value of $" << svalue << ", ";
cout << "the agent's commission is $" << commission;
}
else if(svalue>25000)
{
commission=svalue*20/100;
cout << "For a total sale value of $" << svalue << ", ";
cout << "the agent's commission is $" << commission;
}
getch();
}
This program takes in the total sale value as a screen input from the user.
The program then calculates the agent's commission with the help of the 'IF-ELSE' command as follows :
5% if the total sale value is less than or equal to $10000.
10% if the total sale value is less than or equal to $25000.
20% if the total sale value is greater than $25000. It then outputs the agent's commission using the 'cout' command.
The program then calculates the agent's commission with the help of the 'IF-ELSE' command as follows :
5% if the total sale value is less than or equal to $10000.
10% if the total sale value is less than or equal to $25000.
20% if the total sale value is greater than $25000. It then outputs the agent's commission using the 'cout' command.
Asterisks Programming in C TYPE- 1
/*This is a 'C'program which print the following
Asterisk pattern as output:- *
**
***
****
***** & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=1;i<=n;i++)//start of loop.This loop control the row of pattern print
{
for(j=1;j<=i;j++)//nested loop.This loop print the asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of loop
getch();
}//end of program
Asterisks Programming in C TYPE- 2
/*This is a 'C'program which print the following
Asterisk pattern as output:- *
**
***
****
***** & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n,k; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=1;i<=n;i++)//start of loop.This loop control the row of pattern print.
{
for(k=1;k<=n-i;k++)//nested loop.This loop control the space of pattern.
printf(" ");
for(j=1;j<=i;j++)//nested loop.This loop print the asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of loop
getch();
}//end of program
Asterisks Programming in C TYPE- 3
/*This is a 'C'program which print the following
Asterisk pattern as output:-
* *
** **
*** ***
**** ****
*********** & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n,k; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=1;i<=n;i++)//start of loop.This loop control the row of pattern print.
{
for(j=1;j<=i;j++)//nested loop.This loop print the left side asterisk of pattern.
printf("*");
for(k=1;k<=2*(n-i);k++)//nested loop.This loop control the space between asterisk pattern.
printf(" ");
for(j=1;j<=i;j++)//nested loop.This loop print the right side asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of loop
getch();
}//end of program
Asterisks Programming in C TYPE- 4
/*This is a 'C'program which print the following
Asterisk pattern as output:-
**********
**** ****
*** ***
** **
* * & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n,k; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=n;i>=1;i--)//start of loop.This loop control the row of pattern print.
{
for(j=1;j<=i;j++)//nested loop.This loop print the left side asterisk of pattern.
printf("*");
for(k=1;k<=2*(n-i);k++)//nested loop.This loop control the space between asterisk pattern.
printf(" ");
for(j=1;j<=i;j++)//nested loop.This loop print the right side asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of loop
getch();
}//end of program
Asterisks Programming in C TYPE- 4
/*This is a 'C'program which print the following
Asterisk pattern as output:- *
**
***
****
*****
****
***
**
* & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=1;i<=n;i++)//start of first loop(use for incresing of number of asterisk).This loop control the row of pattern print.
{
for(j=1;j<=i;j++)//nested loop.This loop print the asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of first loop
for(i=(n-1);i>=1;i--)//start of second loop(use for decresing of number of asterisk).This loop control the row of pattern print
{
for(j=1;j<=i;j++)//nested loop.This loop print the asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of second loop
getch();
}//end of program
How to: Run and Compile C Programming in Ubuntu?
13-11-2011
So guys my lab final exams are coming thats why I have to do practices of shell script and C programs in linux for Os lab Examination.
Here I will show How to Run and Compile C Programming in Ubuntu?
Just a few step and you will able to run this C in ubuntu...
so here we go ...
This is the source code of a very simple program which I am going to compile and run:
#include<stdio.h>
int main(){
int pid,ppid;
pid=getpid();
ppid=getppid();
printf("PID=%d\n,PPID=%d\n",pid,ppid);
}
To Compile:
gcc<space>file_name.c<space>-o<space>file_name
Here I will show How to Run and Compile C Programming in Ubuntu?
Just a few step and you will able to run this C in ubuntu...
so here we go ...
This is the source code of a very simple program which I am going to compile and run:
#include<stdio.h>
int main(){
int pid,ppid;
pid=getpid();
ppid=getppid();
printf("PID=%d\n,PPID=%d\n",pid,ppid);
}
To Compile:
First, save your C programs as file_name.c. Your file name can be any but the extension has to be .c. After that, open the terminal and type:
gcc<space>file_name.c<space>-o<space>file_name
I saved my file by process.c name
e.g.
gcc process.c -o process.c
If your program don’t have any errors, it will successfully compiled.
To Run:
After you successfully, compiled the program, you can see a file_name.out in the place where you save your program.
To run the program, type:
./file_name
e.g.
./process
OUTPUT: PID=1020
PPID=1052
If this post help you then pass the comment
Admin
YTA
C Programming :
Swapping by using two variables
This program is about swapping any two numbers by using 2 variables....
#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
clrscr();
printf("enter the number a and b :");
scanf("%d%d",&a,&b);
a=a+b;//step 1
printf("after step 1: a=%d\n\n",a);
b=a-b;//step 2
printf("after step 2: b=%d\n\n",b);
a=a-b;//step 3
printf("after step 3: a=%d\n\n",a);
printf("final swapping: \na=%d \nb=%d",a,b);
getch();
}
This program is about swapping any two numbers by using 2 variables....
#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
clrscr();
printf("enter the number a and b :");
scanf("%d%d",&a,&b);
a=a+b;//step 1
printf("after step 1: a=%d\n\n",a);
b=a-b;//step 2
printf("after step 2: b=%d\n\n",b);
a=a-b;//step 3
printf("after step 3: a=%d\n\n",a);
printf("final swapping: \na=%d \nb=%d",a,b);
getch();
}
if you have any query regarding the program then free to ask at youthtalentauzzar@gmail.com
C Programming :
Swapping
23/10/2011
This is Swapping program in C language by using 3 variables...
#include<stdio.h>
#include<conio.h>
void main(){
int a,b,c;
clrscr();
printf("enter the number a and b :");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("\na=%d \nb=%d",a,b);
getch();
}
Simply take 2 variables like a=5 and b=6 and our desire result will be a=6 and b=5.
Taking a and b as input and take one more variable c by using this we will do swapping.
c=a; // by this instruction value of c will be 5 and now value of a will be the same as 5
a=b; // by this instruction value of a will be 6 and now value of b will be the same as 6
b=c; // by this instruction value of b will be 5
if you have any query regarding the program then free to ask at youthtalentauzzar@gmail.com
C Progrmmaing :
Fibonacci series
19/10/2011
#include<stdio.h>
#include<conio.h>
void main()
{
int t,a,q,x,y;
clrscr();
printf("\t\tITS A FIBBONACCI PROGRAM\n");
printf("\tEnter the desire number of terms:");
scanf("%d",&a); //taking number as input.
x=0; y=1; // initializing value for variable x and y.
t=2; // initailly value of t will be 2 because we will print 0 and 1 from different instruction.
q=0;//initialising variable q as 0,since it is calculating sum & summation identity is 0.
printf("%d\t",x);//printing the value of 1st term of series.
printf("%d\t",y);//printing the value of 2nd term of series.
while(t<a)//starting of loop,loop will execute untill condition is satisfied.
{
q=x+y;
x=y;
y=q;
printf("%d\t",q);//printing the value of rest term of series upto which you have desired.
t=t+1;//incrementaion statement.
}//end of loop.
getch();
}// end of program.
19/10/2011
#include<stdio.h>
#include<conio.h>
void main()
{
int t,a,q,x,y;
clrscr();
printf("\t\tITS A FIBBONACCI PROGRAM\n");
printf("\tEnter the desire number of terms:");
scanf("%d",&a); //taking number as input.
x=0; y=1; // initializing value for variable x and y.
t=2; // initailly value of t will be 2 because we will print 0 and 1 from different instruction.
q=0;//initialising variable q as 0,since it is calculating sum & summation identity is 0.
printf("%d\t",x);//printing the value of 1st term of series.
printf("%d\t",y);//printing the value of 2nd term of series.
while(t<a)//starting of loop,loop will execute untill condition is satisfied.
{
q=x+y;
x=y;
y=q;
printf("%d\t",q);//printing the value of rest term of series upto which you have desired.
t=t+1;//incrementaion statement.
}//end of loop.
getch();
}// end of program.
if you have any query regarding the program then free to ask at youthtalentauzzar@gmail.com
C Programming :
Armstrong Number
19/10/2011
#include<stdio.h>
#include<conio.h>
void main(){
int a,t,y,q;// taking variables.
clrscr();//to clear the screen .
printf("\t\t\t***This is Armstrong Program***\n\n\n\n");
printf("\tEnter a dirsire number:");
scanf("%d",&a); //taking the number as input.
t=0;
t=a;//now the value of variable t and a are same.
q=0; y=0;
while(a>0){ //from here the main work start for calculating the armstrong number.
y=a%10;
q=q+(y*y*y);
a=a/10;
}end of the loop.
if(t==q) //comparing the value of the variables t and q
printf("\n\nYupp !! This is a ARMSTRONG NUMBERR :)");
else
printf("\n\nSoRRy!! This is not a ARMSTRONG NUMBER :(");
getch();
}//end of the program.
19/10/2011
#include<stdio.h>
#include<conio.h>
void main(){
int a,t,y,q;// taking variables.
clrscr();//to clear the screen .
printf("\t\t\t***This is Armstrong Program***\n\n\n\n");
printf("\tEnter a dirsire number:");
scanf("%d",&a); //taking the number as input.
t=0;
t=a;//now the value of variable t and a are same.
q=0; y=0;
while(a>0){ //from here the main work start for calculating the armstrong number.
y=a%10;
q=q+(y*y*y);
a=a/10;
}end of the loop.
if(t==q) //comparing the value of the variables t and q
printf("\n\nYupp !! This is a ARMSTRONG NUMBERR :)");
else
printf("\n\nSoRRy!! This is not a ARMSTRONG NUMBER :(");
getch();
}//end of the program.
if you have any query regarding the program then free to ask at youthtalentauzzar@gmail.com
This comment has been removed by a blog administrator.
ReplyDelete