CSC141 Introduction to Computer Programming
ASSIGNMENT NO # 01:
Names
|
IBRAR AHMAD
|
Registration Numbers
|
FA19-BEE-083
|
Class
|
BEE
|
Instructor’s Name
|
Dr. Syed Junaid Nawaz
|
ASSIGNMENT Assessment
QUESTION NO
|
MARK
|
Question no 1
|
|
Question no 2
|
|
Question no 3
|
|
Question no 4
|
|
Question no 5
|
|
Question no 6
|
|
Total
|
|
QUESTION NO # 1
1
2
3
4
5
6
7
8
9
10
11
12 | #include <stdio.h>
void main(){
int i,f=1,num;//delare i and num and assign 1 to f as integer
printf("Input the number : "); //we show to user to imput a number
scanf("%d",&num); // we scan for integer int type and assign it to num
for(i=1;i<=num;i++) // here we run for loop till i is less or equal to num
f=f*i; //here we put factorial formula
printf("The Factorial of %d is: %d\n",num,f); //we show the result to user
} |
QUESTION NO #2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 | #include <stdio.h>
int zerofound(int a,int b,int c, int d)
{
return (a==0 || b==0 || c==0 || d==0);
}
int main()
{
int a,b,c,d;
/* Input number from user */
printf("Enter 1st number: ");
scanf("%d", &a);
printf("Enter 2nd number: ");
scanf("%d", &b);
printf("Enter 3rd number: ");
scanf("%d", &c);
printf("Enter 4th number: ");
scanf("%d", &d);
//calling function if all number = 0 then it print zero found otherwise not found
if(zerofound(a,b,c,d))
{
printf("Zero found.");
}
else
{
printf("Zero is not found.");
}
return 0;
} |
| |
QUESTION NO# 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | #include <stdio.h>
int main() {
int a,b,sum;
printf("Enter an first integer: ");
scanf("%d", &a);
printf("Enter an second integer: ");
scanf("%d", &b);
sum = a+b;
// true if num is perfectly divisible by 2
if(sum % 2 == 0)
printf("%d+%d=%d is even.",a,b,sum);
else
printf("%d+%d=%d is odd.",a,b,sum);
return 0;
} |
|
|
QUESTION NO # 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | #include <stdio.h>
int main()
{
int i,j,n;
printf("Enter number of rows: ");
scanf("%d",&n);
i=1;
while(i<=n)
{
j=0;
while(j++<(n-i))
{
printf(" ");
}
j=0;
while(j<i)
{
printf("*");
j++.
}
printf("\n");
i++;
}
return 0;
} |
QUESTION NO #5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | #include <stdio.h>
int main()
{
int n, c, k;
printf("Enter number of rows\n");
scanf("%d", &n);
for (k = 1; k <= n; k++)
{
for (c = 1; c <= n-k; c++)
printf(" ");
for (c = 1; c <= 2*k-1; c++)
printf("*");
printf("\n");
}
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= k; c++)
printf(" ");
for (c = 1 ; c <= 2*(n-k)-1; c++)
printf("*");
printf("\n");
}
return 0;
} |
| |
QUESTION NO# 6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | #include <stdio.h>
void main()
{
int num, i, j, m = 1; // declare local variables
printf (" Enter the number to define the columns: \n");
scanf ("%d", & num);
for (i = 1; i <= num; i++)
{
for (j = 1; j <= i; j++)
{
printf( "* ");
}
printf("\n");
}
for (i = num-1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf ("* ");
}
printf("\n");
}
return 0;
} |
|
|
إرسال تعليق