Assignment# 3: Some Programming Examples
Assignment# 3: Some Programming Examples
MUHAMMAD FAROOQ
Serial# 28
Ex.1: Write a program that will be having two integer constant, two float constant and two character
constant defined at the time declaration. Display them in the following format.
int 1 int 2
float 2 float 1
char 1 char 2
char1 int 1 float 1
float 1 char 2 int 2
coding:
#include<stdio.h>
main ()
{
int a=5 , b=10;
float c=3.5, d=5.12;
char x='A', y='Z';
printf("%d %d",a,b);
printf("\n%f %f",d,c);
printf("\n%c %c",x,y);
printf("\n%c %d %f",x,a,d);
printf("\n%f %c %d",c,y,b);
getch();
return 0;
}
Screenshot:
Assignment# 3: some programming examples.
MUHAMMAD FAROOQ
Serial# 28
Ex.2: Write a program having 2 character and 3 float constant declared at the time of definition. Display
them in the following format.
__
__
float 1 (8spaces) char 1
char 2 (8spaces) float 2 (8spaces) float 3
__
char 1 (8spaces) char 2
__
__
(8spaces) float 3 (8spaces) float 1 (8spaces) float 2
Coding:
#include<stdio.h>
main ()
{
char x='A', y='Z';
float c=3.5, d=5.12, e=6.5;
printf("\n\n%f \t %c",c,x);
printf("\n%c \t %f \t %f",y,d,e);
printf("\n\n%c \t %c",x,y);
printf("\n\n\n\t%f \t %f \t %f",e,c,d);
getch();
return 0;
}
Screenshot:
Assignment# 3: some programming examples.
MUHAMMAD FAROOQ
Serial# 28
Ex.3: Write a program that will be taking two int values as input and will be displaying in the following
format.
int 1
int 2
__
__
int 1 (8spaces) int 2
Coding:
#include<stdio.h>
main ()
{
int x,y;
getch();
return 0;
}
Screenshot:
Assignment# 3: some programming examples.
MUHAMMAD FAROOQ
Serial# 28
Ex.4: Write a program that will be asking the user to enter a character, a float and two integers and display
them in the following format.
char
__
int 2 (8spaces) int 1
__
__
float
__
__
char (8spaces) float (8spaces) int 1 (8spaces) int 2
Coding: Screenshot:
#include<stdio.h>
main ()
{
int a , b;
float c;
char d;
printf("Enter character:");
scanf("%c",&d);
printf("Enter First integer:");
scanf("%d",&a);
printf("Enter Second integer:");
scanf("%d",&b);
printf("Enter Float:");
scanf("%f",&c);
printf("%c",d);
printf("\n\n%d\t%d",b,a);
printf("\n\n\n%f",c);
printf("\n\n\n%c\t%f\t%d\t%d",d,c,a,b);
getch();
return 0;
}
Assignment# 3: some programming examples.
MUHAMMAD FAROOQ
Serial# 28
Ex.5: Write a program that will be taking two integers values as input from the user. Calculate their sum
and display in the following format.
Coding:
#include<stdio.h>
main ()
{
int a, b, sum;
getch();
return 0;
}
Screenshot:
Assignment# 3: some programming examples.
MUHAMMAD FAROOQ
Serial# 28
Ex.6: Write a program that will be taking three integer values as input and will calculate the sum of first
and last values and product of all three values. Calculate double of Sum and half of product and display
them as following.
Coding:
#include<stdio.h>
main ()
{
int a, b, c, sum, product, dos;
float hop;
printf("\nSum:%d",sum);
printf("\nProduct:%d",product);
printf("\nDouble of Sum is:%d",dos);
printf("\nHalf of Product is:%f",hop);
getch();
return 0;
}
Screenshot: