New Text Document
New Text Document
New Text Document
*/
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
// return 0;
}
************************************************************************
/* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N
*/
#include <stdio.h>
#define N 16
int main(void) {
int n;
int val = 1;
printf("\t n \t
2^n\n");
printf("\t================\n");
for (n=0; n<=N; n++) {
printf("\t%3d \t %6d\n", n, val);
val = 2*val;
}
return 0;
}
/* It prints out :
n
2^n
================
0
1
1
2
2
4
3
8
4
16
5
32
6
64
7
128
8
256
9
512
10
1024
11
2048
12
4096
13
8192
14
16384
15
32768
16
65536
*/
********************************************************************************
*********************************
/* homework1.c -- This is how the code for the first homework
*
appears when we have a single block letter.
*
In our Unix system you can compile, link,
*
*
*
*/
#include <stdio.h>
void blockg(void);
#include <stdio.h>
int main(void)
int n;
int sum;
int current;
int lcv;
{
/*
/*
/*
/*
*/
*/
*/
the number
int dimes;
int quarters;
int temp, left;
//
//
//
//
********************************************
/* true.c -- What are in C the values of TRUE and FALSE?
*/
#include <stdio.h>
int main(void) {
printf("The value of 1<2 is %d\n", (1<2));
printf("The value of 2<1 is %d\n", (2<1));
}
/* The program prints out
The value of 1<2 is 1
The value of 2<1 is 0
*/
********************************************************************************
*******************************************
/* fibo.c -- It prints out the first N Fibonacci
*
numbers.
*/
#include <stdio.h>
int main(void) {
int n;
int i;
int current;
int next;
int twoaway;
/*
/*
/*
/*
/*
The
The
The
The
The
6
7
8
9
8
13
21
34
*/
********************************************************************************
****************************************
/* funcs.c -- Examples of function declarations, definitions, and use
*/
#include <stdio.h>
/* Examples of declarations of functions */
void square1(void);
int area(int b, int h); /* Example of a function with two input parameters
and with integer return value */
/* Main program: Using the various functions */
int main (void) {
square1();
/* Calling the square1 function */
square2(7); /* Calling the square2 function using 7 as actual
parameter corresponding to the formal parameter i */
printf("The value of square3() is %d\n", square3()); /* Ysing the square3
function */
printf("The value of square4(5) is %d\n", square4(5)); /* Using the square4
function with 5 as actual parameter corresponding to i */
printf("The value of area(3,7) is %d\n", area(3,7)); /* Using the area
function with 3, 7 as actual parameters corresponding
to b, h respectively */
}
/* Definitions of the functions */
/* Function that reads from standard input an integer and prints
it out together with its sum */
void square1(void){
int x;
printf("Please enter an integer > ");
scanf("%d", &x);
printf("The square of %d is %d\n", x, x*x);
}
/* Function that prints i together with its sum */
void square2(int i){
printf("The square of %d is %d\n", i, i*i);
}
printf("\nNumber is Odd");
}
getch ();
}*******************************************************************************
************************************
WAP to find out Positive or Negative (IF-ELSE)
void main ()
{
int a;
clrscr ();
printf ("Enter the value of A: ");
scanf("%d",&a);
if (a>=0)
{
printf ("Number is Positive");
}
else
{
printf("Number is Negative");
}
getch ();
}
********************************************************************************
************************************
WAP to find out TOTAL SALARY with (IF-ELSE)
void main ()
{
long int sal,hra,ta,ts;
clrscr ();
printf ("Enter Salary: ");
scanf("%ld",&sal);
if (sal>=5000)
{
hra=sal*.10;
ta=sal*.07;
}
else
{
hra=sal*.08;
ta=sal*.05;
}
ts=sal+hra+ta;
printf ("\n\nTotal Salary is Rs.%ld", ts);
getch ();
}
********************************************************************************
*************************************
WAP to find out Year is leap or not (IF-ELSE)
void main ()
{
int a;
clrscr ();
printf ("Enter the Year: ");
scanf("%d",&a);
if (a%4==0)
{
printf ("\nYear is Leap");
}
else
{
printf("\nYear is not Leap");
}
getch ();
}
********************************************************************************
**************************************
WAP to find the factorial of the number (1x2x3x4)
void main ()
{
int fact=1,no;
clrscr();
printf ("Enter any number: ");
scanf ("%d",&no);
do
{
fact=fact*no;
no--;
}
while (no>0);
printf ("\nFactorial is %d",fact);
getch ();
}
********************************************************************************
***************************************
WAP to find out Quardratic Equation (d=b2-4ac)
void main ()
{
int a,b,c,d;
clrscr ();
printf ("Enter A: ");
scanf ("%d",&a);
printf ("Enter B: ");
scanf ("%d",&b);
printf ("Enter C: ");
scanf ("%d",&c);
d= (b*b)-(4*a*c);
printf ("\nAnswer is %d",d);
getch ();
}
********************************************************************************
******************************************
WAP to find out power of any number
#include
#include
void main ()
{
double no,r,res;
clrscr ();
printf ("Enter Number : ");
scanf ("%lf",&no);
printf ("Enter raised : ");
scanf ("%lf",&r);
res=pow(no,r);
printf ("\nResult is %.2lf", res);
getch ();
}
********************************************************************************
*******************************
WAP to find out total marks & Percentage of three subjects
void main ()
{
int m1,m2,m3;
float tm,per;
clrscr ();
printf ("Enter M1: ");
scanf ("%d",&m1);
printf ("Enter M2: ");
scanf ("%d",&m2);
printf ("Enter M3: ");
scanf ("%d",&m3);
tm=m1+m2+m3;
per=(tm/300*100);
printf ("\nTotal Marks are %.2f",tm);
printf ("\nPercentage is %.2f",per);
getch ();
}
********************************************************************************
****************************
WAP to find out total marks of three subjects
void main ()
{
int m1,m2,m3,tm;
clrscr ();
printf ("Enter M1: ");
scanf ("%d",&m1);
printf ("Enter M2: ");
scanf ("%d",&m2);
printf ("Enter M3: ");
scanf ("%d",&m3);
tm=m1+m2+m3;
printf ("\nTotal Marks are %d",tm);
getch ();
}
********************************************************************************
*****************************
WAP to print Odd numbers from 1 to 20
void main ()
{
int a;
clrscr ();
a=1;
while (a<=20)
{
if (a%2==1)
printf ("\n%d",a);
a++;
}
getch ();
}