-->

program to get value of f(x)

// program to get value of f(x)=x2+2x+3
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,f_x;
printf(“enter x \n”);
scanf(“%f”,&x);
f_x=(pow(x,2)+2*x+3); //pow() function exists inside math.h
printf(“the result is=%f\n”,f_x);
getch();
}

input and output programs

continued.......

P19)write a program to get value of  f(x)=x2+2x+3.Here, x is a variable.
                                                                                                                  solution
P20)Write a program to get total and percentage of a student whose marks in different subjects are given below.
                                                                                                       
subjects marks
english45
maths65
physics45
chemistry45
                                                                                                                   solution

P21)Write a program to get value of quadratic equation ax2+bx+c.Here, symbols have as usual meaning. (use simple method)                                                              
                                                                                                                   solution

P22)Write a program to convert number of days into year,months and days.
                                                                                                                    solution

P23)Write a program to convert number of seconds into hour,minutes and seconds.
                                                                                                                    solution

P24)write a program to know ascii value of entered character.
                                                                                                                    solution
                                                                                                               

program to get value of expression y raised to power of x

// program to get value of xy
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,y;
float result;
printf(“enter x and y\n”);
scanf(“%f%f”,&x,&y);
result=pow(x,y); //pow() function exists inside math.h
printf(“the result is=%f\n”,result);
getch();
}


note: similarly you can get others' value.

program to get 'n' th power of expression

// program to get 'n' th power of given expression
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,n;
float result;
printf(“enter a and b\n”);
scanf(“%f%f”,&a,&b);
printf("enter value of 'n'\n");
scanf("%f",&n);
result=pow((a+b),n); //pow() function exists inside math.h
printf(“the result is=%f\n”,result);
getch();
}


note: this program gives you/us value of
(a+b)2 or (a+b)3 or any other.

program to get sum of three nos.



// program to get sum of three nos
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
float sum;
printf(“enter nos. for a,b and c\n”);
scanf(“%f%f%f”,&a,&b,&c);
sum=a+b+c;
printf(“the sum is=%f\n”,sum);
getch();
}


program to input a string and display it

// program to input string and display it
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
printf(“enter a string\n”);
gets(a); // we can also use scanf("%[^\n]",a);
puts(a); // we can also use printf("the string =%s",a);
getch();
}

note:
1)gets() function is used to input a string and
puts() is used to display that string.
may be with space or without space.
2) If we use scanf("%[^\n]",a) then it accepts space for a string but if we use scanf("%s",a) then it does not accept string with space.so better to use gets or scanf("%[^\n",a);

program to input and display single character



// program to input single character and display it
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf(“enter a single character\n”);
scanf(“%c”,&a); // we can also use a=getchar()
printf(“the character=%c\n”,a); // we can also use putchar(a)
getch();
}

note:
getchar() function is only used to input a single character and
putchar() is only for one character display