Chandigarh University: Assignment 1 Subject:-Computer Programing Subject:-UCT-144 Submitted To: - Ms. Anupam Mittal
Chandigarh University: Assignment 1 Subject:-Computer Programing Subject:-UCT-144 Submitted To: - Ms. Anupam Mittal
Assignment 1
Subject:- Computer programing
Subject:-UCT-144
Submitted to:- Ms. Anupam Mittal
Submitted by:-Sunil Kumar
UID:-19BEM1001
Section A
Q1 Creat a c program to check whether a given number is
positive or negative?
Ans #include<stdio.h>
Void main ()
{
Int a;
printf(“enter a number:\n”);
scanf(“%d”,&a);
if(a>0)
{
printf(“positive”);
}
else
{
Printf(“negative”)
}
}
Q2 Create a program to display the patten like right angle
triangle with a number which will repeate a number a
row?
Ans #include<stdio.h>
Int main()
{
Int a,i,j;
printf(“enter a number to be repeated in patten:\”);
scanf(“%d”,&a);
printf(“\n\n”);
for(j=0; j<=1;j++
{
printf(“%d”,a);
}
printf(“\n”);
}
printf(“\n”);
printf(“\n”);
for(j=0;j<=i-1;j++)
{
printf(“ ”)
}
for(j=2;j>=1;j--)
{
printf(“%d”,a);
}
printf(“\n”);
}
return 0;
}
Q3 Create a program to find the factorial value of a
number.Also write the algorithim and draw a flowchart.
Ans #include<stdio.h>
Int main()
{
Int I,num;
printf (“enter a number;\n”);
scanf(“%d”,&num);
printf(“factors of number are:”);
print(“\n\n1\n”);
for(j=1;j<=num;j++)
{
If(num%j==0)
{
printf(“%d\n”,i);
}
}
return 0;
}
ALGORITHM
1. START
2. Enter a number “num”
3. Print “1”
4. For (j=2;j<=num;j++)
5. If(num%i==0)
6. Print “1”
7. End
Q4 Develop a flowchart to find the prime number
between 1 to 100 ?
Ans
START
INITIALISE
i,j,t
no
i=2 i++
end
I<=1
print
(“%d”,i)
yes
t=0
yes
j=2 j++
break no If(t== no
j<=i/2
0)
yes
If(i%j= no
t=1;
=0)
Q5 Devolop an algorithm ( a step by step process) for a
program to calculate the sum and average of two
numbers entered by the user of the programe.
Ans ALGORITHIM
1. START
2. ENTER TWO NUMBERS X AND Y
3. SUM=X+Y
4. MULTIPLICATION=X*Y
5. PRINT “SUM”
6. PRINT “MUTIPLICATION”
7. END