C programming
Assignment
[Link]
ARADWAJ
ROLL NO 56
BBA IT 1ST YEAR
C programming
assignment
1. To check wether the given number is
even or odd
The code for the above programm
#include <stdio.h>
#include <stdlib.h>
int main()
{ int num;
printf ("enter an integer:");
scanf("%d",&num);
if (num%2==0)
printf ("%d is a even",num);
else
{printf("%d is a odd",num);}
return 0;
}
[Link] check wether the given number
is positive or negative
The code for the above programm
#include <stdio.h>
1
#include <stdlib.h>
1
int main()
{
double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");
} else
printf("You entered a positive number.");
return 0;
}
[Link] and colours
#include <stdio.h>
#include <conio.h>
int main()
{ int num;
("cls");
printf ("enter an integer:");
scanf("%d",&num);
if (num==1)
printf ("VOILET");
else
if (num==2)
printf("INDIGO");
else
if (num==3)
printf("BLUE");
else
if (num==4)
printf("GREEN");
else
if (num==5)
printf("YELLOW");
else
if (num==6)
printf("ORANGE");
else
if (num==7)
printf("RED");
return 0;
}