Documente Academic
Documente Profesional
Documente Cultură
Answer 1)b . This is algorithm for for calculating the sum of 3 number
3
The formula for the sum of 3 number can be sum=∑number i
I=1
Step 1: let the sum be initially set to 0 .
Step 2: let I be initially 1
Step 3: take the ith number from the user
Step 4: add the ith number to the sum
Step 5: increase the value at I by 1.
Step 6: check if the value of I is less than or equal to 3 ; then go to step 4.
All 3 number are similarly entered by the user , until I becomes
greater than 3 . than go to step 7.
Step 7: output the sum .
Q. 2 Write short notes on the following :
a) VARIABLES :
A variables is a data name that may be used to store a data value . unlike
constant that remain unchanged during the execution of a program , a
variables may take different values at different times during execution .
Some example :-
1. they must be began with letter . some system permit underscore as the
first letter .
2. ANSI standard recognizes a length of 31 character . however the
length should not be normally more than eight character . since only
the first eight character are treated as significant by many compiler .
3. uppercase and lower case are significant . that is the variable Total is
not the same as total or TOTAL .
4. the variable name should not be a keyword .
5. white space is not allowed .
INTEGRAL TYPE
START
R
EAD
A
AND
B
YES NO
Is
A>B
Print Print
A
B
END
b) To calculate sum of first 10 odd numbers.
START
SUM=
0
N=0
N=N+1
N%2!=0 NO
YES
SUM=SUM+N
YES IS
N=10?
NO
PRINT
SUM
END
Q. 3 Accept principal amount, rate of interest, and duration from the
user. Display Interest Amount and Total Amount (Principal +
Interest).
Solution :-
#include<conio.h>
#include<stdio.h>
void main(void)
{clrscr();
printf("principal=");
printf("rate=");
printf("time=");
interst=((p*r*t)/100);
total=p+interst;
getch();
}
Q. 4 Accept the salary of an employee from the user. Calculate the
gross salary on the following basis:
Basic HRA DA .
#include<conio.h>
#include<stdio.h>
float basic,hra,da,gross_salary,basic1,basic2;
void main(void)
{clrscr();
printf("basic= ");
if(basic<=4000){hra=10; da=50;}
getch();
}
Q. 5 Accept any number from the user. Display whether the number is
divisible by 100 or not.
Solution :-
#include<conio.h>
#include<stdio.h>
int num,i ;
void main(void)
{clrscr();
printf( "enter the number \n");
scanf( "%d", &num);
if(num%100==0)
{
printf("divide by 100 ");
}
else
printf(" not divided by 100 ");
getch();
}
Q. 6 Accept a month in digit from the user. Display the month in
words. If number is not between 1 and 12 display message “Invalid
Month”. (Use ‘switch’)
Solution:-
#include<conio.h>
#include<stdio.h>
int num,i ;
void main(void)
{
char ch ;
clrscr();
while(!(num==100))
{
printf("\n
************************************************\n") ;
printf("\n Choose Month in digit for exit press e \n");
scanf( "%d", &num);
switch( num)
{
case 1:
{
printf ("\n Month in word January" ) ;
break;
}
case 2:
{
printf ("\n Month in word \" February\" \n " ) ;
break;
}
case 3:
{
printf ("\n Month in word \"March\" \n " ) ; break;
}
case 4:
{
printf ("\n Month in word \"April\" \n" ) ; break;
}
case 5:
{
printf ("\n Month in word \"May\" \n" ) ; break;
} case 6:
{
printf ("\n Month in word \"June\" \n" ) ; break;
}
case 7:
{
printf ("\n Month in word \"July\" \n" ) ; break;
}
case 8:
{
printf ("\n Month in word \"August\" \n" ) ; break;
}
case 9:
{
printf ("\n Month in word \"September\" \n " ) ; break;
}
case 10:
{
printf ("\n Month in word \"October\" \n" ) ; break;
}
case 11:
{
printf ("\n Month in word \"November\" \n " ) ; break;
}
case 12:
{
printf ("\n Month in word \"December\" \n " ) ; break;
}
default :
{
Solution:-
#include<conio.h>
#include<stdio.h>
int i , num,p ,num1,j;
void main(void)
{clrscr();
printf("Enter intial number as 50 \n");
scanf( "%d" , &num1);
printf("Enter last number as 150 \n");
scanf( "%d", &num);
printf("Display all prime number between 50 and 150 \n\n");
for(j=num1 ; j<=num; j++)
{
p=0;
for(i=2; i<=num ; i++)
{
if (j%i==0)
{
p++;
}
}
if(p==1||num==1)
{
printf("Prime NO. is = %d\n", j);
}
}
getch();
}
Q. 8 Write a program to print the following pattern:
a) 1 b) 1
12 22
123 333
1234 4444
12345 55555
Solution :-
a) 1
12
123
1234
12345
#include<conio.h>
#include<stdio.h>
int num,i,j ,k,cnt=0;
void main(void)
{
clrscr();
printf("enter the number 5 \n") ;
scanf( "%d", &num);
printf("pattern are following \n\n");
for(i=1;i<num+1;i++)
{
cnt++;
for(k=0;k<cnt;k++)
{
printf("%d",k+1);
}
printf("\n");
}
getch();
}
b) 1
22
333
4444
55555
Solution:-
#include<conio.h>
#include<stdio.h>
int num,i,j ,k,cnt=0;
void main(void)
{clrscr();
printf("enter the number 5 \n") ;
scanf( "%d", &num);
printf("pattern are following \n\n");
for(i=1;i<num+1;i++)
{ cnt++;
for(k=0;k<cnt;k++)
{
printf("%d", i);
}
printf(" \n\n");
}
getch();
}
Q. 9 Write a program to swap the values of two numbers. Do this
Solution:-
#include<conio.h>
#include<stdio.h>
int a,b,*i,*j ;
{ int temp ;
temp=*q;
b=*p;
a=temp ; }
void main(void)
{clrscr();
printf("a=");
scanf( "%d",&a);
printf("b=");
scanf("%d",&b);
func(&a,&b);
getch(); }
Q. 10 Write a program to accept 10 values in an integer array. Display
the number of odd, even, and negative numbers.
Solution :-
#include<conio.h>
#include<stdio.h>
int i,cnt=0,t=0,nt=0 ;
int a[10];
void main(void)
{
clrscr();
printf("Enter the 10 numbers u want :- \n ");
for(i=0;i<10;i++)
{
scanf( "%d", &a[i]);
}
printf( "10 number are following :-\n ");
for(i=0;i<10;i++)
printf("%d\n",a[i]);
printf("\n Following are even values :-\n");
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{ cnt=cnt+1;
printf( "\n%d \n",a[i]);
}
}
printf("\ntotal even no. are = %d \n" ,cnt );
printf("\n Following are 0dd values :-\n");
for(i=0;i<10;i++)
{
if(a[i]%2!=0)
{ nt=nt+1;
printf( "\n%d\n",a[i]);
}
}
printf("\ntotal odd no. are = %d \n" ,nt );
printf("\n Following are negative values :-\n");
for(i=0;i<10;i++)
{
if(a[i]<0)
{ t=t+1;
printf( "\n%d\n",a[i]);
}
}
printf("\ntotal negative no. are = %d \n" ,t );
getch();
}
Q. 11 Create a structure to store the employee number, name,
department and basic salary. Create a array of structure to accept
and display the values of 10 employees.
Solution :-
#include<stdio.h>
#include<conio.h>
int i, student;
float temp[10];
struct personal
char name[20];
char name1[20];
int basic_salary;
int age;
};
int main(void)
clrscr();
scanf("%d",&student);
for(i=0;i<student;i++)
{ printf("\n");
printf("**************************************************
*****************************");
printf("\n");
printf("\n");
printf("\n");
scanf("%d", &st[i].age );
printf("\n");
printf( "\n");
for(i=0;i<student;i++)
printf( "\n");
printf("**************************************************
*****************************");
printf("\n");
printf("\n");
printf("\n");
getch();