ఒకే రకమైన output in 5 different ways (regular/ for/ while/ do..while)
//program to print marks in 4 subjects without using arrays
#include<stdio.h>
#include<conio.h>
void main()
{
int marks1=90, marks2=95,marks3=99, marks4=90;
clrscr();
printf("marks in subject1 = %d",marks1);
printf("marks in subject2 = %d",marks2);
printf("marks in subject3 = %d",marks3);
printf("marks in subject4 = %d",marks4);
getch();
}
void main()
{
int marks1=90, marks2=95,marks3=99, marks4=90;
clrscr();
printf("marks in subject1 = %d",marks1);
printf("marks in subject2 = %d",marks2);
printf("marks in subject3 = %d",marks3);
printf("marks in subject4 = %d",marks4);
getch();
}
--------------------------------------------------------------------------------------
#include<stdio.h>#include<conio.h>
void main()
{
// datatype nameof_the_variable[lentgh of array];
int marks[]={90,95,99,90};
clrscr();
printf("marks in subject1 = %d",marks[0]);
printf("marks in subject2 = %d",marks[1]);
printf("marks in subject3 = %d",marks[2]);
printf("marks in subject4 = %d",marks[3]);
getch();
}
void main()
{
// datatype nameof_the_variable[lentgh of array];
int marks[]={90,95,99,90};
clrscr();
printf("marks in subject1 = %d",marks[0]);
printf("marks in subject2 = %d",marks[1]);
printf("marks in subject3 = %d",marks[2]);
printf("marks in subject4 = %d",marks[3]);
getch();
}
--------------------
/*నాలుగసార్లు printf వ్రాయనవసరం లేకుండా we can use for loop or while loop or do while loop */
// using while loop
#include<stdio.h>
#include<conio.h>
//datatype function_name(datatype, datatype)
void main()
{
int i=0,marks[4]={90,95,99,90};
while(i<4)
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
i=i+1;
}
}
//datatype function_name(datatype, datatype)
void main()
{
int i=0,marks[4]={90,95,99,90};
while(i<4)
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
i=i+1;
}
}
--------------------------------------------------------------------------------------
//using do..while()
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,marks[4]={90,95,99,90};
do
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
i=i+1;
}while(i<4);
}
void main()
{
int i=0,marks[4]={90,95,99,90};
do
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
i=i+1;
}while(i<4);
}
----------------------------------------------------------------------------------------
//using for loop
#include<stdio.h>
#include<conio.h>
#include<conio.h>
void main()
{
int i,marks[4]={90,95,99,90};
for(i=0;i<4;i++)
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
}
}
{
int i,marks[4]={90,95,99,90};
for(i=0;i<4;i++)
{
printf("marks in subject %d=%d \n",i+1,marks[i]);
}
}
---------------------------------------------------------------------------------------------
తెరమీద
marks in subject 1 = 90
marks in subject 2 = 95
marks in subject 3 = 99
marks in subject 4 = 90
marks in subject 2 = 95
marks in subject 3 = 99
marks in subject 4 = 90
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.