LB PS Unit 2 and 3
LB PS Unit 2 and 3
3. Write a c program to print the following details with the use of printf().
1
23
456
7 8 9 10
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("1\n");
printf("2 3\n");
printf("4 5 6\n");
printf("7 8 9 10\n");
getch();
}
*
**
***
****
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*\n");
printf("* *\n");
printf("* * *\n");
printf("* * * *\n");
getch();
}
&
&&
&&&
&&&&
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("&\n");
printf("& &\n");
printf("& & &\n");
printf("& & & &\n");
getch();
}
4. Write a c program to print the multiplication table of given number from
the user.
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B;
clrscr();
printf("enter the value A= ");
scanf("%d",&A);
printf("%d*1=%d\n",A,A*1);
printf("%d*2=%d\n",A,A*2);
printf("%d*3=%d\n",A,A*3);
printf("%d*4=%d\n",A,A*4);
printf("%d*5=%d\n",A,A*5);
printf("%d*6=%d\n",A,A*6);
printf("%d*7=%d\n",A,A*7);
printf("%d*8=%d\n",A,A*8);
printf("%d*9=%d\n",A,A*9);
printf("%d*10=%d\n",A,A*10);
getch();
}
22. Write a c program to convert days into year, months and remaining days.
Year=days/365
Month=(days-year*365)/30
Remdays=(days –year *365 – month*30)
#include<stdio.h>
#include<conio.h>
void main()
{
int days,year,months,RD;
clrscr();
printf("enter days: ");
scanf("%d",&days);
year=days/365;
months=(days-year*365)/30;
RD=(days-year*365-months*30);
printf("%d days = %d year %d months and %d remining days",days,year,months,RD);
getch();
}
23. Write a c program to find the value of reminder and quotient,
Rem=dividend/divisor
Quo= dividend%divisor
#include<stdio.h>
#include<conio.h>
int main()
{
int dividend,divisor,rem,quo;
clrscr();
printf("enter dividend: ");
scanf("%d",÷nd);
printf("enter divisor: ");
scanf("%d",&divisor);
if(divisor == 0)
{
printf("error : divisor cannot be zero.\n");
}
rem=dividend / divisor;
quo=dividend % divisor;
printf("remainder: %d\n",rem);
printf("quotient: %d\n",quo);
getch();
}
24. Write a c program to check whether a temperature is below freezing point
or not. condition is= if temperature is <32 then it is below freezing point
otherwise it is above the freezing point.
#include <stdio.h>
#include <conio.h>
void main()
{
float temperature;
clrscr();
printf (“enter the temperature is Celsius: ”);
scanf(“%f”,&temperature);
temperature<0?printft(“the temperature is below freezing point \n”):printf(“the
temperature is above freezing point \n”);
getch();
}
25. Write a c program to find the student is pass or not. (use global variable)
calculate the total of 4 subject mark.
check condition : if total>60 then student will be pass otherwise fail.
#include<stdio.h>
#include <conio.h>
void main()
{
Int pass, fail, sub1, sub2, sub3, sub4, total;
clrscr();
printf(“enter marks for sub1:\n");
scanf(“%d”,&sub1);
printf(“enter marks for sub2:\n”);
scanf(“%d” ,&sub2);
printf(“enter marks for sub3:\n”);
scanf(“%d”,&sub3);
printf(“enter marks for sub4:\n");
scanf(“%d”,&sub4);
total-sub1+sub2+sub3+sub4;
(total>60)?printf(“student has passed\n”):printf(“student has failed\n”);
getch();
}
333
2222
11111
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" 5\n");
printf(" 4 4\n");
printf(" 3 3 3\n");
printf(" 2 2 2 2\n");
printf(" 1 1 1 1 1\n");
getch();
}