UYT Compressed Compressed
UYT Compressed Compressed
ASSIGNMENT
SUBMITTED TO : SUBMITTED BY:
Ajaz Husain warsi
Name : Masoud Tayyab
Branch : Electrical &
Computer Science
Enrolment NO : 2300102114
Group : 02
1
C PROGRAMMING
(INTRODUCTION)
What is C?
C is a general-purpose programming language created by
Dennis Ritchie at the Bell Laboratories in 1972.
It is a very popular language, despite being old. The main
reason for its popularity is because it is a fundamental
language in the field of computer science.
C is strongly associated with UNIX, as it was developed to
write the UNIX operating system.
Why Learn C?
It is one of the most popular programming language in the
world
If you know C, you will have no problem learning other
popular programming languages such as Java, Python,
C++, C#, etc, as the syntax is similar
C is very fast, compared to other programming languages,
like Java and Python
C is very versatile; it can be used in both applications and
technologies
2
PROGRAMMINGS
1.Write a C program find sum and average of three numbers.
Program:
#include<stdio.h>
#include<conio.h>
Int main()
{
int a,b,c,sum;
float avg;
clrscr();
printf(“\n ENTER ANY THREE NUMBERS: \n”);
scanf(“%d%d%d”,&a,&b,&c);
sum=a+b+c;
avg=sum/3;
printf(“\n SUM=%d \n”,sum);
printf(“\n AVERAGE=%.2f”,avg);
getch();
return 0;
}
3
OUTPUT
ENTER THREE NUMBERS:
34
32
13
SUM=70
AVERAGE=23.00
4
printf(“\n Entered number is negative.\n Please enter a
positive integer.”);
getch();
return 1;
}
While(num>0)
{
digit=num%10;
sum+=digit;
num/=10;
}
printf(“\n Sum of individual digits=%d \n”,num);
getch();
return 0;
}
OUTPUT
Please enter a positive integer:
-45
Entered number is negative.
Please enter a positive integer.
68
sum of individual digits=14
5
3.Fibonacci Sequence is defined as follows: the first and second
terms in the sequence are 0 and 1. Subsequent terms are found
by adding the preceding two terms in the sequence. Write a C
program to generate the first n terms of the sequence.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int f0,f1,f,i,n;
clrscr();
printf(“\nEnter the Number Of Elements \n”);
scanf(“%d\t”,&n);
f0=0;
f1=1;
printf(“\nFibonacci SeriesFor The First %d Terms: \n”,n);
i=0;
while(i<n)
{
printf(“%d\t”,f0);
f=f0+f1;
f0=f1;
i=i+1;
}
6
getch();
}
OUTPUT
Enter The NumberOf Elements:
16
Fibonacci Sequence For The First 16 Terms
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
7
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
printf("\n%d Is An Armstrong Number\n.", num);
else
printf("\n%d Is Not An Armstrong Number\n.", num);
getch();
return 0;
}
OUTPUT
Enter a three-digit integer: 124
124 is not an Armstrong number.
Enter a three-digit integer: 153
153 is an Armstrong number.
9
}
OUTPUT
Series of prime numbers.
Enter any number to generate prime numbers.
34
The prime numbers between 1 to 34
23 571113 17 19232931
11
the result (Consider the operators +,-,*,/,% and use Switch
Statement.)
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
char ch;
clrscr();
printf("Enter your operator(+, -, /, *, %)\n");
scanf("%c", &ch);
printf("Enter the values of a and b\n");
scanf("%d%d", &a, &b);
switch(ch)
{
case '+': c = a + b;
printf("Addition of two numbers is %d", c);
break;
case '-': c = a - b;
printf("Subtraction of two numbers is %d", c);
break;
12
case '*': c = a * b;
printf("Multiplication of two numbers is %d", c);
break;
case '/': c = a / b;
printf("Remainder of twonumbers is %d", c);
break;
case '%': c = a % b;
printf("Quotient of two numbers is %d", c);
break;
default: printf("Invalid operator");
break;
}
getch();
}
OUTPUT
Enter your operator(+, -, /, *, %)
*
Enter the values of a and b
12
23
Multiplication of two numbers is 276
13