Ict

You might also like

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

COMSATS UNIVERSITY ISLAMABAD

ABBOTABBAD CAMPUS

SUBMITTED BY: AROOJ FATIMA , MAHZAIB

REG NO: SP24 – BCS –( 207 , 165 )

Submitted To: Mam Qurat-ul-ain

Course: Introduction to ICT


QUESTION 1:

PART A

Write a program for a Bank account in which show user name, account
number and use menu driven program which has following options: a) Show
Balance b) Debit Amount c) Credit Amount d) Exit When any
option/operation execute name and account number will be at the top

#include <stdio.h>

#include <string.h>

int main() {

char name[50];

int accountNumber;

float balance = 0.0;

printf("Enter the account holder's name: ");

scanf("%49s", name);

printf("Enter the account number: ");

scanf("%d", &accountNumber);

int choice;
float amount;

while (1) {

printf("\nMenu:\n");

printf("1. Show Balance\n");

printf("2. Debit Amount\n");

printf("3. Credit Amount\n");

printf("4. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("\nAccount Holder: %s\n", name);

printf("Account Number: %d\n", accountNumber);

printf("Current balance: $%.2f\n", balance);

break;

case 2:

printf("\nAccount Holder: %s\n", name);

printf("Account Number: %d\n", accountNumber);

printf("Enter the amount to debit: $");


scanf("%f", &amount);

if (amount > balance) {

printf("Insufficient balance!\n");

} else {

balance -= amount;

printf("Amount debited successfully. New balance: $%.2f\n",


balance);

break;

case 3:

printf("\nAccount Holder: %s\n", name);

printf("Account Number: %d\n", accountNumber);

printf("Enter the amount to credit: $");

scanf("%f", &amount);

balance += amount;

printf("Amount credited successfully. New balance: $%.2f\n", balance);

break;

case 4:

printf("Exiting the program...\n");

return 0;
default:

printf("Invalid choice! Please try again.\n");

break;

return 0;

}
OUTPUT:
FLOW CHART
START
"Enter the account
holder's name"

"Enter the account


number"

Loop Start
(while (1))

Display Menu

Input User Choice

T
(choice == 1) Display Account
Information
F T
"Enter Debit
(choice == 2)
Amount"
F
T "Enter Credit
(choice == 3) Amount"
F
T "Exiting the
(choice == 4) program..."
F

END
QUESTION 1
PART B
A company decides to give bonus to all its employees on ‘Eid. A 5% bonus on
salary is given to the male workers and 10% bonus on salary to the female
workers. Write a program to enter the salary and gender of the employee. If
the salary of the employee is less than 10,000 the employ gets extra 2% bonus
on salary. Calculate the bonus that has to be given to the employee and display
the salary that employee will get.

#include <stdio.h>
int main() {
float salary, bonus;
char gender;
printf("Enter M for Male and F for Female: ");
scanf("%c", &gender);
if (gender == 'M' || gender == 'm') {
printf("Enter Salary: ");
scanf("%f", &salary);
if (salary > 10000) {
bonus = salary * 0.05; // 5% bonus
} else {
bonus = salary * 0.07; // 7% bonus
}
} else if (gender == 'F' || gender == 'f') {
printf("Enter Salary: ");
scanf("%f", &salary);
if (salary > 10000) {
bonus = salary * 0.1; // 10% bonus
} else {
bonus = salary * 0.12; // 12% bonus
}
}
else
printf("\nInvalid input\n");
salary += bonus;
printf("Bonus: %.2f\nSalary: %.2f\n", bonus, salary);
return 0;
}

PROGRAM
OUTPUT:
FLOW CHART:

Start

Input Gender

F T
Gender == 'M' or 'm'?

F
Enter Salary
gender == 'F' || gender
== 'f' T
F T
Salary > 10000?

Invalid input Enter Salary


bonus = bonus = salary
salary * 0.07; * 0.05

Salary > 10000?


F T

bonus = bonus =
salary * 0.12 salary * 0.1

Salary = Salary + Bonus

Output Bonus and Salary

END
QUESTION 2
Part A
#include <stdio.h>
int main() {
int number, sum = 0;
printf("Enter a 5-digit number: ");
scanf("%d", &number);
if (number < 10000 || number > 99999) {
printf("Invalid input! Please enter a 5-digit number.\n");
return 1;
}
while (number > 0) {
sum += number % 10;
number /= 10;
}
printf("The sum of the digits is: %d\n", sum);
return 0;
}

PROGRAM:
OUTPUT:
PART B

#include <stdio.h>

int main() {
float exam1, exam2, sports, activity1, activity2, activity3;
float total_exam, total_activities, total_weighted_score;

// Input marks for exams


printf("Enter the marks for Exam 1: ");
scanf("%f", &exam1);
printf("Enter the marks for Exam 2: ");
scanf("%f", &exam2);

// Input marks for sports


printf("Enter the marks for Sports: ");
scanf("%f", &sports);

// Input marks for activities


printf("Enter the marks for Activity 1: ");
scanf("%f", &activity1);
printf("Enter the marks for Activity 2: ");
scanf("%f", &activity2);
printf("Enter the marks for Activity 3: ");
scanf("%f", &activity3);

// Calculate total marks for exams (50% weightage)


total_exam = ((exam1 + exam2) / 2) * 0.50;

// Calculate total marks for sports (20% weightage)


total_activities = ((activity1 + activity2 + activity3) / 3) * 0.30;

// Calculate total marks for activities (30% weightage)


float total_sports = sports * 0.20;

// Calculate the total weighted score


total_weighted_score = total_exam + total_sports + total_activities;

// Display the total weighted score


printf("The total weighted score of the student is: %.2f\n",
total_weighted_score);

return 0;
}

Program:
OUTPUT:
Part C
LAB TASK 9
Question No: 1
#include<stdio.h>
int main(){

int a = 0;
if(a=10)
printf("%d",a);
return 0;
}
Program:

OUTPUT:
CORRECT THE PROGRAM:
#include<stdio.h>
int main(){

int a = 0;
if(a==10)
printf("%d",a);
return 0;
}
PROGRAM

OUTPUT:
Question No 2:
#include <stdio.h>
int main()
{
int a = 2 , b=3 , c=4 ;
if(b==2){
a=10;
}
else
c=10;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
PROGRAM:

OUTPUT:
Question NO 3:
#include <stdio.h>
int main()
{
int a = 2 , b=3 , c=4 ;
if(a&&b){
c=10;
}
else
c=20;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
PROGRAM:
OUTPUT:

Question No 4:

#include <stdio.h>
int main()
{
int a = 2 , b=3 , c=4 ;
if(a||b||c){
c=10;
}
else
c=20;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
OUTPUT:

Question No 5:

#include <stdio.h>
int main()
{
int a = 2 , b=3 , c=4 ;
if(a)
if(b)
c=10;
else
c=20;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}

PROGRAM:
OUTPUT:

Question No 6:

#include <stdio.h>

int main()
{
int a = 2 , b=3 , c=4 ;
if(a == 0 || b >= c && c> 0)
if(a && b)
c=10;
else
c=20;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
PROGRAM:
OUTPUT:

Question No 7:

#include <stdio.h
int main()
{
int a = 2 , b=3 , c=4 ;
if(a = b)
c++;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
PROGRAM:

OUTTPUT:
Question NO 8:

#include <stdio.h>
int main()
{
int a = 2 , b=3 , c=4 ;
if(a = b < c){
c++;
a--;
}
++b;
printf("\na = %d\nb = %d\nc = %d",a,b,c);
return 0;
}
OUTPUT:

Question No 9:

#include <stdio.h>
int main()
{
int i = 3;
switch(i){
case 0:
printf("\nCustomers are dicey");
case 1+0:
printf("\nMarkets are pricey");

case 4/2:
printf("\nlnverstors are moody");
case 8%5:
printf("\nAt least employees are good");
}
return 0;
}

PROGRAM:
OUTPUT:

Question No 10:
#include <stdio.h>
int main()
{
int k ;
float j = 2.0;
switch(k = j+1){
case 3:
printf("\nTrapped");
break;
default:
printf("\nCaught!");
}
return 0;
}
OUTPUT:

Question No 11:

#include <stdio.h>
int main()
{
int ch = 'a' + 'b';
switch(ch){
case 'a':
case 'b':
printf("\nYou entered b");
case 'A':
printf("\na as in ashar");

case 'b'+'a':
printf("\nYou entered a and b");
}
return 0;
}

OUTPUT:
Question No 12:

#include <stdio.h>
int main()
{
int i = 1;
switch(i-2){
case -1:
printf("\nFeeding fish");
case 0:
printf("\nWeeding grass");

case 1:
printf("\nmending roof");
default:
printf("\njust to survive");
}
return 0;
}
OUTPUT:
Question No 13:

#include <stdio.h>
int main()
{
int temp ;
scanf("%d",&temp);
switch(temp){
case (temp <= 20):
printf("\nOooooooh ! Damn cool");
case (temp > 20 && temp <= 30):
printf("\nRain rain here again");
case (temp > 30 && temp <= 40):
printf("\nWish I am on Everest");
default:
printf("\nGood old nagpur weather");
}
return 0;
}
OUTPUT:
Correct the program:

#include <stdio.h>
int main()
{
int temp ;
scanf("%d",&temp);
switch(temp){
case 1:
printf("\nOooooooh ! Damn cool");
break;
case 2:
printf("\nRain rain here again");
break;
case 3:
printf("\nWish I am on Everest");
break;
default:
printf("\nGood old nagpur weather");
}
return 0;
}
OUTPUT:
LAB TASK 8
Question No 1:
#include <stdio.h>

int main()
{
int k , num = 30;
k = (num>5?(num<=10?100:200):500);
printf("num = %d",num);

return 0;
}
PROGRAM:
OUTPUT:

Question No 2:
#include <stdio.h>

int main()
{
int a = 15 , b = 10 , c = -3 ,res;
res = a>b&&a>c;
printf("res = %d",res);
return 0;
}
OUTPUT:

Question No 3:
#include <stdio.h>

int main()
{
int a = 5, _c = -3 ;
_c = a+3*a++;
printf("_c = %d\t a = %d",_c,a);
return 0;
}

OUTPUT:
Question No 4:
#include <stdio.h>

int main()
{
int x = 100 , 30 ,50;
printf("x = %d",x);
x = (100,30,50);
printf("x = %d",x);
return 0;
}
OUTPUT:

CORRECT THE ERROR:


#include <stdio.h>
int main()
{
int x = 100;
printf("x = %d",x);
x = (100,30,50);
printf("\nx = %d",x);
return 0;
}
OUTPUT:

Question No 5:

#include <stdio.h>
int main()
{
int x = 3 , y = 5 , z = 7;
int a , b;
a = x * 2 + y / 5 - z * y;
b = ++x * (y-3) / 2 - z++ * y;
printf("\n a = %d",a);
printf("\n b = %d",b);
return 0;
}
OUTPUT:

Question No 6:
#include <stdio.h>
int main()
{
int a = 4 , b= 1 , c = -3 , res;
res = a > b && a < c ;
printf("\n %d ",res);
res = a == c || a < b ;
printf("\n %d ",res);
res = b > 10 || b && c < 0 || a > 0;
printf("\n %d ",res);
res = (a/2.0 == 0.0 && b/2.0 !=0.0)||c<0.0;
printf("\n %d ",res);
return 0;
}

OUTPUT:
Question No 7:
#include <stdio.h>
int main()
{
int a = 10;
printf("\na = %d",5+a++);
printf("\na = %d",5+ ++a);
return 0;
}

OUTPUT:
Question No 8:
#include <stdio.h>
int main()
{
int a = 15 , b=-10 , _=3;
_=a-b;
printf("\n_ = %d",++_);
return 0;
}

OUTPUT:
Question No 9:
#include <stdio.h>
int main()
{
const char var = 'A';
++var;
printf("\nvar = %c",var);
return 0;
}

OUTPUT:
CORRECT THE ERROR:
We can not change the value of constant
#include <stdio.h>
int main()
{
char var = 'A';
++var;
printf("\nvar = %c",var);
return 0;
}

OUTPUT:
Question No 10:
#include <stdio.h>
int main()
{
char var = 'B';
var+=2;
var++;
printf("\nvar = %c , var = %d",var , var);
return 0;
}

OUTPUT:
Question No 11:
#include <stdio.h>
int main()
{
int a = 3;
int b = ++a;
printf("value of b = %d",b);
a = b++;
b = a++;
printf("%d %d",b,a);
return 0;
}
OUTPUT:

Question No 12:
#include <stdio.h>
int main()
{
int a,b=3;
char c = 'A';
a = b+c;
int b = ++a;
printf("value of a = %d",a);
return 0;
}
OUTPUT:

CORRECT THE PROGRAM:


(one variable is declared two times that’s why error occur )

#include <stdio.h>
int main()
{
int a,b=3;
char c = 'A';
a = b+c;
int B = ++a;
printf("value of a = %d",a);
return 0;
}
OUTPUT:

You might also like