Wednesday, October 17, 2007

C-Programes


  1. WAP to find greatest among two rnumbers using conditional operators?

  2. WAP to find area of triangle using hero’s formula?
  3. Admission to PGDCA class is suspected to following condition:
    marks in matriculation >=50%
    marks in chemistry >=40%
    marks in physics >=45%
    total in all three subjects >=180
    Scan the marks from keyboard. Write a program to display list of eligible candidates.
  4. WAP that will read value of x & evaluate the following function:
    i. y = 5 if x>0
    ii. y = 0 if x=0
    iii. y = -5 if x<0
  5. WAP to find sum of digits?
  6. WAP to check if the given number is peridrom?
  7. WAP to print fibonaci series?
  8. WAP to find factorial of any number?
  9. WAP to check if the entered number is prime or not?
  10. WAP to Print
    *
    * *
    * * *
    * * * *
    * * * * *
  11. WAP a program to swap two numbers using pointers?
  12. WAP to Print
    *
    * *
    * * *
    * * * *
    * * * * *
  13. WAP to print
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
  14. Write a recursion function to find factorial of n?
  15. Write a recursion function to print fibonaci series up to n terms?
  16. WAP to find sum of array elements?
  17. WAP to find product of two matrix?
  18. WAP to find transpose of a matrix?
  19. Write a function to print array elements using pointers?
  20. WAP to find greatest element in 2-D array?
  21. Write a function to find length of string?
  22. Write a function to reverse a string?
  23. WAP to compare two strings
  24. Design a structure named student to store data about a student which contains following info.:
    i. Data items type
    ii. Roll.no. int
    iii. Name char[20]
    iv. Class char[10]
    v. Marks int
    Assume that there are not more than 50 students .W.a.p to input data about students &
    Output stored items?
  25. Demonstrate concepts of nested structures.Consider employee, address, contact as structur

49 comments:

Gurpreet Singh Kamboj said...

hello sir
could you tell what is pointer of pointer.
i could not understand in book.
so please provide some help.

Sonia Sharma said...

W.A.P TO FIND FIBONACCI SERIES OF 20 TERMS
void main()
{
int a=0, b=1,c=1,i;
clrscr();
for(i=1;i<=20;i++)
{
printf("%d",c;
c=a+b;
a=b;
b=c;
}
getch();
}

Sonia Sharma said...

hello sir
this block is not accepting the html tags < > ; cannot accept the header files
thats why i m not able to define header files in programs

Sonia Sharma said...

void main()
{
float a,b,c,area,s;
clrscr();
printf("enter the values of 3 s :");
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
s=(a+b+c)/2;
area= sqt(s*(s-a)*(s-b)*(s-c));
printf("area of triangle = %f",area);
printf("\n");
getch();
}

Prof. Sukhdev Singh said...

Try this for adding include files

<include stiod.h>

Sonia Sharma said...

W.A.P TO PRINT *
*
* *
* * *
* * * *
* * * * *
void main()
{
int i,n,j;
clrscr();
printf("\n enter the value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=1;j++)
printf("*");
printf("\n %d",j);
}
getch();
}

Sonia Sharma said...

W.A.P TO SUM OF TWO DIGITS

void main()
{
int a,b,sum;
clrscr();
printf("\n enter the values of a,b ");
scanf(" %d%d",&a,&b,);
sum= a+b;
printf("%d",sum);
getch();
}

Sonia Sharma said...

sir it also dont accepted in this type of defining header files

Prof. Sukhdev Singh said...

http://w3schools.com/html/html_entities.asp
vist this page it ll definatly help u

Unknown said...

W.A.P to check the number is peridrom or not?
void main()
{
int n,r;
printf("\n Enter a number;");
scanf("%d",&n);
r=reverse(n);
if(n==r)
printf("%d is peridrom",n);
else
printf("%d is not a palindrom",n);
}
int reverse(int num)
{
int rev=0;
while(num>0)
{
rev=rev*10+num%10;
num=num/10;
}
return(rev);
}

Unknown said...

W.A.P to check the number is prime or not?
void main()
{
int n,r;
printf("\n Enter a number:");
scanf("%d",&n);
r=prime(n);
if(r==1)
printf("%d is prime number",n);
else
printf("%d is not a prime number",n);
}
int prime( int n)
{
int p=1;
int s,d;
s=sqrt(n);
for(d=2;d<=5;d++)
{
if(n%d==0)
{
p=0;
break;
}
}
return(p);
}

Unknown said...

W.A.P to check the greater number?
void main()
{
int m,n;
printf("\n enter the value of m&n:");
scanf("%d%d",&m,&n);
if(m>n)
{
printf("%d is greater",m);
}
else
{
printf("%d is greater",n);
}
}

Unknown said...
This comment has been removed by the author.
Unknown said...

#include< stdio.h>

Unknown said...
This comment has been removed by the author.
Gurpreet Singh Kamboj said...

sir i am gurpreet . I found your site as a good soruce of programs . i have done MCA.. sir can i use your site to interact with other members..for the purpose of making concepts clear..this will help me as well as others. i want to share my programing skills with your students.

Gurpreet Singh Kamboj said...

for chandni....
you can also write this to find greater no.


(m>n ? printf("m is greater"):printf("n is greater"));

Unknown said...

hello gurpreet....
your concept is also right but we are following this pattern for writting programs in the college as i hav written in my program just to simplify things.
but thanks to you, for sharing this n please continue to discuss
the points like this in future.

Unknown said...

W.A.P to swap two numbers?
main()
{
int a=5;
int b=10;
void swap(int,int);
swap(a,b);
printf("%d%d",a,b);
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("%d%d",a,b);
}

Unknown said...
This comment has been removed by the author.
Unknown said...

void main()
{
int n,f;
int fact(int);
printf("enter value of n to find factorial");
scanf("%d",&n);
f=fact(n);
printf("factorial=%d",f);
getch();
}
int fact(int x)
{
int i,p=1;
for(i=1;1<=x;i++)
{
p=p*i;
}
return(p);
}

honey said...
This comment has been removed by the author.
honey said...

hello friend i m sonia and my names is going to be changed as sarif_jatt37

Unknown said...

W.A.P to find the factorial of any number?
#include<stdio.h>
#include<conio.h>

unsigned long int factorial(int n)
{
unsigned long int f=1;
int i;
for(i=n;i>=1;i--)
f=f*i;
return f;
}
void main()
{
int n;
printf("\n Enter a no.");
scanf("%d",&n);
printf("factorial of %d=%ld",n,factorial(n));
}

Unknown said...

hey friends its me sonia2220
as gunnu

Unknown said...

write a program to find the averege of three numbers
ans: friends please add urself the header files like stdio.h and conio.h
main()
{
int a,b,c,sum;
float avg;
clrscr();
printf("enter the value of a:");
scanf("%d",&a);
printf("enter the value of b:");
scanf("%d",&b);
printf("enter the value of c:");
scanf("%d",&c);
sum=a+b+c;
avg= sum/3.0;
printf("\n average of a,b,c is= %5.2f",avg);
}

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...

i have missing brackets in temprature progrma and mathematical equation program
please add bracket at the place of zero in print f statement

Unknown said...

DECLARATIONS IN C LANGUAGE
ANS
Informally, a variable (also called an object) is a place you can store a value. So that you can refer to it unambiguously, a variable needs a name. You can think of the variables in your program as a set of boxes or cubbyholes, each with a label giving its name; you might imagine that storing a value ``in'' a variable consists of writing the value on a slip of paper and placing it in the cubbyhole.

A declaration tells the compiler the name and type of a variable you'll be using in your program. In its simplest form, a declaration consists of the type, the name of the variable, and a terminating semicolon:

char c;
int i;
float f;


You can also declare several variables of the same type in one declaration, separating them with commas:

int i1, i2;


Later we'll see that declarations may also contain initializers, qualifiers and storage classes, and that we can declare arrays, functions, pointers, and other kinds of data structures.

The placement of declarations is significant. You can't place them just anywhere (i.e. they cannot be interspersed with the other statements in your program). They must either be placed at the beginning of a function, or at the beginning of a brace-enclosed block of statements (which we'll learn about in the next chapter), or outside of any function. Furthermore, the placement of a declaration, as well as its storage class, controls several things about its visibility and lifetime, as we'll see later.

You may wonder why variables must be declared before use. There are two reasons:

It makes things somewhat easier on the compiler; it knows right away what kind of storage to allocate and what code to emit to store and manipulate each variable; it doesn't have to try to intuit the programmer's intentions.
It forces a bit of useful discipline on the programmer: you cannot introduce variables willy-nilly; you must think about them enough to pick appropriate types for them. (The compiler's error messages to you, telling you that you apparently forgot to declare a variable, are as often helpful as they are a nuisance: they're helpful when they tell you that you misspelled a variable, or forgot to think about exactly how you were going to use it.)
Although there are a few places where declarations can be omitted (in which case the compiler will assume an implicit declaration), making use of these removes the advantages of reason 2 above, so I recommend always declaring everything explicitly.

Most of the time, I recommend writing one declaration per line. For the most part, the compiler doesn't care what order declarations are in. You can order the declarations alphabetically, or in the order that they're used, or to put related declarations next to each other. Collecting all variables of the same type together on one line essentially orders declarations by type, which isn't a very useful order (it's only slightly more useful than random order).

A declaration for a variable can also contain an initial value. This initializer consists of an equals sign and an expression, which is usually a single constant:

int i = 1;
int i1 = 10, i2 = 20;


________FINISH__________-

Unknown said...

ARITHMETIC OPERATORS IN C LANGUAGE
ANS:
The basic operators for performing arithmetic are the same in many computer languages:



+ addition
- subtraction
* multiplication
/ division
% modulus (remainder)


The - operator can be used in two ways: to subtract two numbers (as in a - b), or to negate one number (as in -a + b or a + -b).

When applied to integers, the division operator / discards any remainder, so 1 / 2 is 0 and 7 / 4 is 1. But when either operand is a floating-point quantity (type float or double), the division operator yields a floating-point result, with a potentially nonzero fractional part. So 1 / 2.0 is 0.5, and 7.0 / 4.0 is 1.75.

The modulus operator % gives you the remainder when two integers are divided: 1 % 2 is 1; 7 % 4 is 3. (The modulus operator can only be applied to integers.)

An additional arithmetic operation you might be wondering about is exponentiation. Some languages have an exponentiation operator (typically ^ or **), but C doesn't. (To square or cube a number, just multiply it by itself.)

Multiplication, division, and modulus all have higher precedence than addition and subtraction. The term ``precedence'' refers to how ``tightly'' operators bind to their operands (that is, to the things they operate on). In mathematics, multiplication has higher precedence than addition, so 1 + 2 * 3 is 7, not 9. In other words, 1 + 2 * 3 is equivalent to 1 + (2 * 3). C is the same way.

All of these operators ``group'' from left to right, which means that when two or more of them have the same precedence and participate next to each other in an expression, the evaluation conceptually proceeds from left to right. For example, 1 - 2 - 3 is equivalent to (1 - 2) - 3 and gives -4, not +2. (``Grouping'' is sometimes called associativity, although the term is used somewhat differently in programming than it is in mathematics. Not all C operators group from left to right; a few group from right to left.)

Whenever the default precedence or associativity doesn't give you the grouping you want, you can always use explicit parentheses. For example, if you wanted to add 1 to 2 and then multiply the result by 3, you could write (1 + 2) * 3.

By the way, the word ``arithmetic'' as used in the title of this section is an adjective, not a noun, and it's pronounced differently than the noun: the accent is on the third syllable.


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

Unknown said...
This comment has been removed by the author.
Unknown said...

WRITE A PROGRAM TO CONVER ANY DECIMAL NUMBER INTO BINARYU CODED DECIMAL:
ANS:
main()
{
int a[30],n,c=0,m,i=0;
clrscr();
printf("\n ENTER THE NUMBER:");
scanf("%d",&n);
printf("\n binary number is:");
while(n>=1)
{
m= n%2;
a[1]=m;
i=i+1;
c=c+1;
n= n/2;
}
for(i=c;i>=1;i--)
{
printf("%d",a[i]);
}
getche();
}
OUTPUT IS:
ENTER THE NUMBER: 5
BINARY NUMBER IS: 101

Unknown said...

PROGRAM TO FIND SUM OF COSINE SERIES
ANS:
HEADER FILES STDIO.H, CONIO.H, MATH.H
main()
{
float i,n,t,x,m,z;
z=0;
printf("\n enter the limit of the series and value of x:");
scanf("%f%f%f",&m,&x);
t= cos(x);
for(i=1;i<=n;i++)
{
m=pow (t,i);
z=z+m;
}
printf("\n sum of the cosine series is= %f",z);
getche();
}
output is
enter the limit of the series of value of x:13
series is -0.989992

Unknown said...

W.A.P TO DRAW A FLOYD TRIANGLE


main()
{
int n,i,j,k;
clrscr();
printf("\n ENTER THE MAXIMUM NUMBER OF LINES:");
scanf("%d",&n);
k=1;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%3d",k);
k=k+1;
}
printf("\n");
}
getche();
}

Unknown said...

WAP TO CONVERT LOWER CASE CHARACTER INTO UPPER CASE CHARACTER
ANS:
main()
{
char c1,c2;
clrscr();
printf("\n enter a lower case character:");
scanf("%c",&c1);
c2= (c1>='a'&& c1 <='z')? ('A'+c1-'a'):c1;
printf("\n uppercase equivalent is %c\n",c2);
getch();
}

Sonia Sharma said...
This comment has been removed by the author.
Anonymous said...

WAP to find greatest among two numbers using conditional operaters
void main()
{
int a,b;
clrscr();
printf("Enter value ofA=");
scanf("%d",&a);
printf("Enter value ofB=");
scanf("%d",&b);
(a>b)?printf("A is greaterthen b"):printf("B greater Then a");
getch();
}

Anonymous said...

hello sir my name harpreet rollno= 4007 class= PGDCA
/*WAP to find area of triangle using hero's fourmula*/
math.h
void main()
{
float a,b,c,s,area;
clrscr();
printf("Enter side a=");
scanf("%f",&a);
printf("Enter side b=");
scanf("%f",&b);
printf("Enter side c=");
scanf("%f",&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is =%f",area);
getch();
}

/*WAP to find sum of digits?*/
void main()
{
long int n,digit,s=0;
clrscr();
printf("Enter any nuber=");
scanf("%ld",&n);
for(;n!=0;)
{
digit=n%10;
s=s+digit;
n/=10;
}
printf("sum of digit=%ld",s);
getch();
}
/*WAP to print fibonic series?*/
void main()
{
int n,a=1,b=1,c;
clrscr();
printf("Enter any nuber=");
scanf("%d",&n);
printf("%d\n%d",a,b);
for(c=a+b;c<=n;)
{
printf("\n%d",c);
a=b;
b=c;
c=a+b;
}
getch();
}
/*WAP to check if the given number is peridrom?*/
void main()
{
long int n,i,r=0,m;
clrscr();
printf("Enter any number=");
scanf("%ld",&n);
m=n;
while(n!=0)
{
i=n%10;
r=r*10+i;
n=n/10;
}
printf("\nReverse of the number=%ld",r);
if(m==r)
{
printf("\nThe number is peridrom");
}
else
{
printf("\nThe number is not peridrom");
}
getch();
}
/*WAP to find factorial of any number?*/
void main()
{
long int n,f,m;
clrscr();
printf("Enter any number=");
scanf("%ld",&n);
m=n;
for(f=1;n>1;n--)
{
f=f*n;
printf("\n%ld",f);
}
printf("\nfactorial of number is %ld!=%ld",m,f);
getch();
}
/*WAP to check if the entered number is prime or not?*/
void main()
{
int i,n,s=0;
clrscr();
printf("Enter any number=");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
s++;
}
}
if(s==0)
{
printf("\nThe number is prime");
}
else
{
printf("\nThe number is not prime");
}
getch();
}
/*wap to print
*
**
*** */
void main()
{
int i,j,n;
clrscr();
printf("Enter any no=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
/*wap to print
1
22
333 */

void main()
{
int i,j,n;
clrscr();
printf("Enter any no=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}

Unknown said...

gunnu said...
to convert temp from degree centigrade to rahrenheit
ans:
main()
{
float c,f;
printf("\n enter the temprature in degree centigrade:)"
scanf("%f",&c);
f=(1.8*c)+32;
printf("\n FAHERANHET =%f",f);
getche();
}

November 12, 2007 5:25 AM


gunnu said...
program to compute the mathematical function:
please use header files math.h and dos.h
ans:
main()
{
int x,y;
clrscr();
printf("\n enter the value of x:");
scanf("%d",&x);
y=(x!=2)?x<2?5*x*x+3*x:7*x+50:500;
printf(" \n result of y is +%d",y);
getche();
}

November 12, 2007 5:32 AM




Preview

Unknown said...

HOW TO DECLARE A VARIBLE IN C LANGUAGE:
how tWithin limits, you can give your variables and functions any names you want. These names (the formal term is ``identifiers'') consist of letters, numbers, and underscores. For our purposes, names must begin with a letter. Theoretically, names can be as long as you want, but extremely long ones get tedious to type after a while, and the compiler is not required to keep track of extremely long ones perfectly. (What this means is that if you were to name a variable, say, supercalafragalisticespialidocious, the compiler might get lazy and pretend that you'd named it supercalafragalisticespialidocio, such that if you later misspelled it supercalafragalisticespialidociouz, the compiler wouldn't catch your mistake. Nor would the compiler necessarily be able to tell the difference if for some perverse reason you deliberately declared a second variable named supercalafragalisticespialidociouz.)

The capitalization of names in C is significant: the variable names variable, Variable, and VARIABLE (as well as silly combinations like variAble) are all distinct.

A final restriction on names is that you may not use keywords (the words such as int and for which are part of the syntax of the language) as the names of variables or functions (or as identifiers of any kind).

Unknown said...

FUNCTIONS IN C LANGUAGE:
Functions
C provides functions which are again similar most languages. One difference is that C regards main() as function. Also unlike some languages, such as Pascal, C does not have procedures -- it uses functions to service both requirements.

Let us remind ourselves of the form of a function:



returntype fn_name(1, parameterdef2,)



{

localvariables

functioncode

}

Let us look at an example to find the average of two integers:



float findaverage(float a, float b)
{ float average;

> average=(a+b)/2;
return(average);
}

We would call the function as follows:

main()
{ float a=5,b=15,result;

result=findaverage(a,b);
printf("average=%fn",result);
}


Note: The return statement passes the result back to the main program.


void functions
The void function provide a way of emulating PASCAL type procedures.

If you do not want to return a value you must use the return type void and miss out the return statement:



void squares()
{ int loop;

for (loop=1;loop<10;loop++);
printf("%dn",loop*loop);
}

main()

{ squares();
}

NOTE: We must have () even for no parameters unlike some languages.

Unknown said...

PREPROCESSOR STATEMENTS
ANS:

The Preprocessor accepts source code as input and is responsible for

removing comments
interpreting special preprocessor directives denoted by #.
For example

#include -- includes contents of a named file. Files usually called header files. e.g
#include math.h -- standard library maths file.
#include stdio.h -- standard library I/O file
#define -- defines a symbolic name or constant. Macro substitution.
#define MAX_ARRAY_SIZE 100

Unknown said...

harpreet g karo hor kucch karo is site te

Unknown said...

good evening sir!!!!!! kya aap hume dbms ke kucch important question is site pe de sakte hai pgdca level pe

Unknown said...

hello sir!!!!!!!!!!

Unknown said...

if u are online at this site then are u able to give some suggestions about transmission media and value added networks

Anonymous said...

After looking at a handful of the blog articles on your web site, I seriously like your
way of writing a blog. I saved it to my bookmark website list and
will be checking back in the near future. Take a
look at my web site as well and tell me what you think.


Here is my weblog; weight loss reviews