Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Home Work

Programing Fundamental
Department :
BSCS-ll
Roll No:
28
Submitted By :
Hamza Farooq
Submitted To :
Prof. Faheem
Punjab College Pattoki
Question # 01 :
Write a program that find the sum of first twenty odd and even
numbers.
#include <stdio.h>

void main()
{
int i, num, odd_sum = 0, even_sum = 0;

printf("Enter the value of num\n");


scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (i % 2 == 0)
even_sum = even_sum + i;
else
odd_sum = odd_sum + i;
}
printf("Sum of all odd numbers = %d\n", odd_sum);
printf("Sum of all even numbers = %d\n", even_sum);
return 0;
}
Question # 02 :
Write a program that take a number from user and check weather it is
positive or negative once
#include<stdio.h>
int main()
{double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num < 0.0)
printf("This is a negative number.");
else if (num > 0.0)
printf("This is a positive number.");
else
printf("You entered 0.");
return 0;
}
Question # 03:
Write a program that have three numbers check which is largest and
smallest number.
#include<stdio.h>
int main()
{
int a[50],big, small, i, size;
printf("enter size of list:");
scanf("%d",&size);

printf("Enter the %d integer:",size);


for(i=0; i<size ; i++)
scanf("%d",&a[i]);

big=a[0];
for(i=0; i<size; i++)
{
if
(big<a[i])
big=a[i];
}
printf("The largest no is : %d",big);

small=a[0];
for(i=0; i>size; i++)
{
if
(small>a[i])
small=a[i];
}
printf("\nThe smallest no is: %d",small);
return 0;
}
Question # 04 :
Write a program that execute and show your university profile which
contains your name, father name, age, program and semester and
subject name.
#include <stdio.h>
int main()
{
printf(" Punjab College Pattoki \n");
printf(" Student Profile \n");
printf("Name : Hamza Farooq \n");
printf("Father Name : Afzal Farooq \n");
printf("age : Twenty one \n");
printf("program : BSCS \n");
printf("semester : Second Semester\n");
printf("subject Name : Programing Fundamental \n");
return(0);
}
Question # 05 :
Write a program that get records of five persons such as name, father,
class and age
#include<stdio.h>
int main()
{
char name,father, clas; int age;
{
printf("\n Enter name of person =" );
scanf("%s", & name);
printf("\n Enter father name of person =" );
scanf("%s", & name);
printf("\n Enter class of person =" );
scanf("%s", &clas);
printf("\n Enter age of person =" );
scanf("%d", & age);
return 0;
}}

You might also like