ఒకే రకమైన 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();
}

--------------------------------------------------------------------------------------  
#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();
}

--------------------
/*నాలుగసార్లు 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;
}
}
--------------------------------------------------------------------------------------
//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);
}
----------------------------------------------------------------------------------------
//using for loop
#include<stdio.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]);
 }
}

---------------------------------------------------------------------------------------------
తెరమీద
marks in  subject 1 = 90
marks in  subject 2 = 95
marks in  subject 3 = 99
marks in  subject 4 = 90


కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)