0% found this document useful (0 votes)
55 views

Que.1 Write A Program To Print A Hut.: Solution

The document contains 16 questions and solutions for C programming examples. The questions cover topics such as printing patterns, arithmetic operations, conditional statements, loops, functions, data types, and algorithms including prime numbers, palindromes, Armstrong numbers, factorials, Fibonacci series, and number tables. For each question, the solution provided the C code to solve the problem along with sample input/output.

Uploaded by

Priyanka Bhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Que.1 Write A Program To Print A Hut.: Solution

The document contains 16 questions and solutions for C programming examples. The questions cover topics such as printing patterns, arithmetic operations, conditional statements, loops, functions, data types, and algorithms including prime numbers, palindromes, Armstrong numbers, factorials, Fibonacci series, and number tables. For each question, the solution provided the C code to solve the problem along with sample input/output.

Uploaded by

Priyanka Bhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

QUE.1 WRITE A PROGRAM TO PRINT A HUT.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(" _______________ \n");
printf(" /\\ |\n");
printf(" / \\ |\n");
printf(" /____\\____________|\n");
printf(" | | |\n");
printf(" | | |\n");
printf(" |_____|____________|\n");
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.2 WRITE A PROGRAM TO ADD, SUBTRACT, MULTIPLY
AND DIVIDE TWO NUMBERS WITHOUT USING SCANF
FUNCTION.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=2,y=3;
clrscr();
printf("ADDITION=%d\n",a+b);

printf("SUBTRACTION=%d\n",a-b);
printf("MULTIPLICATION=%d\n",a*b);

printf("DIVITION=%d\n",a/b);

getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.3 WRITE A PROGRAM TO ADD, SUBTRACT,
MULTIPLY AND DIVIDE TWO NUMBERS USING SCANF
FUNCTION.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("enter the numbers: ");
scanf("%d%d",&x,&y);
printf("%d is addition\n",x+y);
printf("%d is subtraction\n",x-y);
printf("%d is multiply\n",x*y);
printf("%d is divide\n",x/y);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.4 WRITE A PROGRAM TO FIND AREA AND
CIRCUMFERENCE OF A CIRCLE.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float r;
clrscr();
printf("enter the radius of the circle: ");
scanf("%f",&r);
printf("%f is the area \n",3.14*r*r);
printf("%f is the circumference \n",2*3.14*r);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.5 WRITE A PROGRAM TO CALCULATE SIMPLE
INTEREST USING FLOAT VALUES.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,t,si;
clrscr();
printf("enter the number: ");
scanf("%f%f%f",&p,&r,&t);
si=p*r*t/100;
printf("%f is simple interest",si);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.6 WRITE A PROGRAM TO CHECK WHETHER THE
CANDIDATES AGE IS GREATER THAN 18 OR NOT. IF YES,
DISPLAY MESSAGE”ELIGIBLE FOR VOTING”.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf("enter your age: \n");
scanf("%d",&age);
if(age<18)
printf("not eligible to vote!\n");
else
printf("eligible to vote!\n");
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.7 WRITE A PROGRAM TO CHECK WHETHER THE
ENTERED NUMBER IS EVEN OR ODD.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("ENTER AN INTEGER: ");
scanf("%d",&n);
if(n%2==0)
printf("%d is even.",n);
else
printf("%d is odd.",n);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.8 WRITE A PROGRAM TO FIND MAXIMUM NUMBER
OUT OF THREE NUMBERS.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("ENTER THREE NUMBER: ");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("a is greatest");
else
printf("c is greatest");
}
else
{
if(b>c)
printf("b is greatest");
else
printf("c is greatest");
}
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.9 WRITE A PROGRAM TO GENERATE ELECTRICITY
BILL.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int unit;
float amt,total_amt,sur_charges;
clrscr();
printf("enter total unit consumed: ");
scanf("%d",&unit);
if(unit<=50)
amt=unit*0.50;
else if(unit<=150)
amt=25+((unit-50)*0.75);
else if(unit<=250)
amt=100+((unit-150)*1.20);
else
amt=220+((unit-250)*1.50);
sur_charges=amt*0.20;
total_amt=amt+sur_charges;
printf("electricity bill=Rs.%.2f",total_amt);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.10 WRITE A PROGRAM TO CHECK WHETHER THE
ENTERED NUMBER IS PRIME OR NOT.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,count=0,n;
clrscr();
printf("enter the number: ");
scanf("%d",&n );
for(i=1;i<n;i++)
{
if(n%i==0)
count++;
}
if(count>1)
printf("not prime");
else
printf("prime");
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.11 WRITE A PROGRAM TO CHECK WHETHER THE
NUMBER IS PALINDROME OR NOT.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,revinteger=0,rem,orginteger;
clrscr();
printf("enter an integer: ");
scanf("%d",&n);
orginteger=n;
while(n!=0)
{
rem=n%10;
revinteger=revinteger*10+rem;
n/=10;
}
if(orginteger==revinteger)
printf("%d is a palindrome.",orginteger);
else
printf("%d is not a palindrome.",orginteger);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.12 WRITE A PROGRAM TO CHECK A NUMBER IS
ARMSTRONG OR NOT.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum=0,temp;
clrscr();
printf("enter a number: ");
scanf("%d",&a);
temp=a;
while(a>0)
{
b=a%10;
sum=sum+(b*b*b);
a=a/10;
}
if(temp==sum)
printf("the number is an armstrong number.");
else
printf("the number is not an armstrong number.");
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.13 WRITE A PROGRAM TO PRINT THE REVERSE OF A
NUMBER.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int rem,temp,rev=0;
clrscr();
printf("enter the number: ");
scanf("%d",&temp);
while(temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
printf("%d",rev);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.14 WRITE A PROGRAM TO FIND THE FACTORIAL OF
A NUMBER.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,fact=1;
clrscr();
printf("enter a number: ");
scanf("%d",&n);
for(c=1;c<=n;c++)
{
fact=fact*c;
}
printf("%d\n",fact);
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.15 WRITE A PROGRAM TO GENERATE FIBONACCI
SERIES.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int first=0,second=1,c,n,next=0;
clrscr();
printf("enter the number: ");
scanf("%d",&n);
for(c=0;c<n;c++)
{
if(c<=1)
next=c;
else
{
next=first+second;
first=second;
second=next;
}
printf("%d",next);
}
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]


QUE.16 WRITE A PROGRAM TO PRINT THE TABLE OF A
GIVEN NUMBER.

Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,no=0;
clrscr();
printf("enter a number: ");
scanf("%d",&no);
while(i<=10)
{
printf("%d \n",(no*i));
i++;
}
getch();
}

OUTPUT:-

[Type text] [Type text] [Type text]

You might also like