UNIVERSITY OF SARGODHA
Lahore Campus
Department: Computer Science & IT
Assignment
Subject
Programing Fundamental
Submitted To:
Sir Saqib Ali Ahmad
Submitted By:
Name: REHMAN JAVED
Roll No: BSCS-F17-LC-226
Class: BS (CS)
Section: B
Q 1. Write a program to prompt the user to input 3 integer values and print these values
in ascending and descending order.
#include <stdio.h>
int main()
{
int a,b,c,num;
printf("enter three digits ");
scanf("%d",&num);
printf("Ascending order\n");
a=num/100;
num=num%100;
b=num/10;
num=num%10;
c=num/1;
num=num%1;
printf("%d\n%d\n%d\n",a,b,c);
printf("Descending order\n");
a=c;
c=a/100;
printf("%d\n%d\n%d\n",a,b,c);
getch();
}
Q 2. What will be the output?
Q 3. Input an integer number and display its binary equivalent.
#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter a decimal number: ");
scanf("%d", &n);
printf("%d in binary number is: ", n);
for (c = 31; c >= 0; c--)
{
k = n > c;
if (k & 1)
printf("1");
else
printf("0");
}
printf("\n");
getch();
}
Q 4. Write a program that read the distance between two cities in kilometers and
change it into Meters, Feet, Inches, Centimeters and Millimeters.
#include<stdio.h>
int main()
{
int a,b,c,d,f;
printf ("Enter the distance between two cities in km: ");
scanf ("%d",&a);
b = a * 1000;
c = b * 3.28;
d = c * 12;
f = d * 30;
printf ("\nDistance in meters = %d m",b);
printf ("\nDistance in feets = %d feet",c);
printf ("\nDistance in inches = %d inches",d);
printf ("\nDistance in centimeters= %d cm",f);
getch ();
}
Q 5.
1
234
56789
#include<stdio.h>
int main()
printf("1\n2 3 4\n5 6 7 8 9");
getch();
}
Q6. Write a program to read a year (4 digit integer) and tell whether the given year
is/was a leap year.
#include <stdio.h>
int main()
{
int a;
printf("enter year: ");
scanf("%d",&a);
if(a%4==0)
{
if(a%400==0 && a%100==0)
printf("it is a leap year");
}
else
{
printf("its not a leap year");
}
getch();
}
Q 7.
*****
****
***
**
*
#include <stdio.h>
int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}
return 0;
}