Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views7 pages

Variable Declaration

The document contains multiple C programs demonstrating variable declaration, assignment, and printing for different data types including integers, floats, characters, and strings. It also includes calculations for total and average marks of subjects. Additionally, it provides instructions for saving, compiling, executing, and viewing outputs in a C programming environment.

Uploaded by

noobchaitu980
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)
6 views7 pages

Variable Declaration

The document contains multiple C programs demonstrating variable declaration, assignment, and printing for different data types including integers, floats, characters, and strings. It also includes calculations for total and average marks of subjects. Additionally, it provides instructions for saving, compiling, executing, and viewing outputs in a C programming environment.

Uploaded by

noobchaitu980
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/ 7

//PROGRAM TO DECLARE,ASSIGNING,PRINTING AN INTEGER VARIABLE VALUE

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=123;
clrscr();
printf("\n a=%d",a); //prints garbage value
printf("\n b=%d",b); //It prints value in variable b.
a=12345;
b=1235;
printf("\n a=%d",a);
printf("\n b=%d",b); //It prints value in variable b.
printf("\n a+b=%d",(a+b));
}
//F2 To Save the Program
//Alt+F9 To Compile the progra
//Ctrl+F9 To Execute the program
//Alt+F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor

*/

//program to calculate sum, avg of six subjects marks;


#include<stdio.h>
#include<conio.h>
void main()
{
int mat=67,sci=78,soc=56,hin=99,eng=88,tel=90,tot,avg;
clrscr();
tot=mat+sci+soc+hin+eng+tel;
avg=tot/6;

printf("\n Total Marks=%d",(mat+sci+soc+hin+eng+tel));


printf("\n Average Marks=%d",(mat+sci+soc+hin+eng+tel)/6);
printf("\n Total marks=%d \n Average Marks=%d",tot,avg);
}

//F2 To Save the Program


//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor

//PROGRAM TO DECLARE, ASSIGNING,PRINTING A float VARIABLE VALUE


#include<stdio.h>
#include<conio.h>

void main()
{
float f;
clrscr();
printf("\n f=%f",f); //it prints garbage vlaue
f=987654320.878;
printf("\n f=%f",f);
}
//F2 To Save the Program
//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor

/*PROGRAM TO DECLARE, ASSIGNING, PRINTING A character VARIABLE VALUE


#include<stdio.h>
#include<conio.h>
void main()
{
char ch='#';
clrscr();
printf("\n Ch=%c",ch);
ch='@';
printf("\n Ch=%c",ch);
}
//F2 To Save the Program
//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor
//PROGRAM TO DECLARE, ASSIGNING, PRINTING A character VARIABLE VALUE
#include<stdio.h>
#include<conio.h>
void main()
{
char ch='#',ch1='$',ch2='&';
clrscr();
printf("\n ch=%c \t ch1=%c \t ch2=%c",ch,ch1,ch2);
ch='*',ch1='%',ch2='!';
printf("\n ch=%c \t ch1=%c \t ch2=%c",ch,ch1,ch2);
}
//F2 To Save the Program
//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor
*/

//program to calculate sum,avg of 3 subject


#include<stdio.h>
#include<conio.h>
void main()
{
char m=99,s=99,so=99;
clrscr();
printf("\n Total marks=%d",(m+s+so));
printf("\n Average Marks=%c",(m+s+so)/3);
printf("\n Average Marks=%d",(m+s+so)/3);
}

/*PROGRAM To Declar,assign,print a string variable


#include<stdio.h>
#include<conio.h>
void main()
{
char sname[15]="Rama Krishna";
clrscr();
printf("The Student name is : %s",sname);
}
//F2 To Save the Program
//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor
*/

// PROGRAM To Declar, assign, print a string variable


#include<stdio.h>
#include<conio.h>
#include<string.h> //using the strcpy() function
void main()
{
char sname[15]="Rama Krishna",fname[15]="Gopala Krishna";
char door_no[15]="2-2-2/13A",street[20]="Visakha B Colony";
char city[15]="Srikakulam",phone[10]="224688";
clrscr();
printf("\nThe Student Name is : %s",sname);
printf("\nThe Father Name is : %s",fname);
printf("\nThe Door No is : %s",door_no);
printf("\nThe Street is : %s",street);
printf("\nThe City is : %s",city);
printf("\nThe Phone Number is : %s",phone);
//sname="rama"; //it we can't intiliziage string value with this stmt;
strcpy(sname,"Teja"); //copying string
strcpy(fname,"Appa Rao");
strcpy(door_no,"12-12-12");
strcpy(street,"Gunapalem");
strcpy(city,"Narasannapeta");
strcpy(phone,"123456");
printf("\n\n\nThe Student Name is : %s",sname);
printf("\nThe Father Name is : %s",fname);
printf("\nThe Door No is : %s",door_no);
printf("\nThe Street is : %s",street);
printf("\nThe City is : %s",city);
printf("\nThe Phone Number is : %s",phone);
}
//F2 To Save the Program
//Alt + F9 To Compile the progra
//Ctrl + F9 To Execute the program
//Alt + F5 To View the output screen or user Screen
//Press any key To Come come back to the 'C' Program Editor

//program to decalre, assign, print an integer, character, string, float


variable
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=12345;
float f=123456789.0987;
char ch='$',str[20]="Rama Krishna";
clrscr();
printf("\n a=%d",a);
printf("\n f=%f",f);
printf("\n ch=%c",ch);
printf("\n str=%s",str);
a=4321;
f=987654321.0987;
ch='#';
strcpy(str,"Gopala Krishna");
printf("\n\n a=%d \n f=%f \n ch=%c \n str=%s",a,f,ch,str);
}

You might also like