0% found this document useful (0 votes)
8 views5 pages

ROHAN BHATI - OS Lab-2

Uploaded by

kashishgarg610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

ROHAN BHATI - OS Lab-2

Uploaded by

kashishgarg610
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment 02

Name - Rohan Bhati


Student ID - 2023uai1809
Branch - A.I.D.E

Ques 1: Write Linux C Program for command line argument to print the output in
following format.

Program :
#include<stdio.h>
int main(int argc,char * argv[]){
printf("Hello,welcome to Linux C\nprogramming!\nNo. of argument to the main Program : \n");
printf("%d\n",argc);
for(int i=0;i<argc;i++){
printf("Argument No. %d : %s",i,argv[i]);
printf("\n");
}
return 0;
}

Output :

Ques 2:Write Linux C Program to initialize character, integer, String and float. Each data
declaration will occupy an amount of memory in byte. Print the output in
following pattern

Program :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
int d;
float d2,d1;
char str[20],str2[20],str3[20];
printf("Town name :");
scanf("%[^\n]",str);
getchar();
printf("\n Population :");
scanf("%d",&d);
getchar();
printf("\ncountry :");
scanf("%[^\n]",str2);
getchar();
printf("\ncountry :");
scanf("%[^\n]",str3);
getchar();
printf("\nLocation Latitude : ");
scanf("%f",&d2);
printf("\nLongitude : ");
scanf("%f",&d1);
printf("\nTown name :");
printf("%s",str);
printf("\n Population :");
printf("%d",d);
printf("\ncountry :");
printf("%s",str2);
printf("\ncountry :");
printf("%s",str3);
printf("\nLocation Latitude : ");
printf("%f",d2);
printf("\nLongitude : ");
printf("%f",d1);
printf("\nchar =%ld byte int = %ld bytes float= %ld bytes ",sizeof(char),sizeof(int),sizeof(float));
int mem=0;
mem=sizeof(d)+sizeof(d1)+sizeof(str)+sizeof(d)+sizeof(str2)+sizeof(str3);
printf("\nmemory used :%d \n",mem);
return 0;
}

Output :
Ques 3:Write Linux C Program to print the entire environment variable on the screen.

Program :
#include<stdio.h>
int main(int argc,char *argv[],char*envp[]){
for(int i=0;envp[i]!=NULL;i++){
printf("%s\n",envp[i]);
}
return 0;
}

Output :
Ques 4: Perform arithmetic operation such as +,*,/,- using Linux C Program by taking input from
command line

Program :
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char* argv[]){
float a=0,b=0;
a=atof(argv[1]);
b=atof(argv[2]);
printf("the operation is done %f # %f :",a,b);
printf("\n add :%f ",(a+b));
printf("\n sub :%f ",(a-b));
printf("\n divide :%f ",(a/b));
printf("\n multiply :%f\n",(a*b));
return 0;
}

Output :

You might also like